Click here to Skip to main content
15,889,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Java
String query="insert into Answers (ID,Ques_ID,Answer) select q.ID,q.Ques_ID,'"+txtboxAddAnswer+"' from Questions q where q.Question='"+passingQuestion+"';";
        Class.forName("com.microsoft.Sqlserver.jdbc.Sqlserverdriver");
        Connection conn=DriverManager.getConnection("jdbc:sqlserver://localhost/H-AHMADRAZA:1433;databaseName=TestJava","testjava","ahmad");
        PreparedStatement st=conn.prepareStatement(query);
        st.executeUpdate(query);
       conn.close();
Posted
Updated 1-Apr-15 6:58am
v2
Comments
Arkadeep De 1-Apr-15 12:41pm    
run the query in your db with a demo data that whether its getting any value from that select query or not.
Member 11504333 1-Apr-15 15:15pm    
its working in db :(
Richard Deeming 1-Apr-15 14:17pm    
Your code is vulnerable to SQL Injection[^].

NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.
Member 11504333 1-Apr-15 15:25pm    
not working. same problem :(
Richard MacCutchan 2-Apr-15 4:17am    
Add some code to check the result of your execute statement; do not just assume that it works.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900