Reputation: 104
I was trying to add details to table but it showing some SQL error
Query is:
t=st1.executeUpdate("insert into stdetails(regno,nam,cid,gender,HouseName,place,guardian,phone,photo,did,Emailid,sem) values("+ reg+",'"+ n +"',"+ c +",'"+g+"','"+ h+"','"+p+"','"+ guar +"','"+ph+"','"+pic+"',"+d+",'"+e+"',"+s+"");
Error is
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
Upvotes: 1
Views: 263
Reputation: 60046
Your are missing the parentheses ) in the end of your query so it should look like :
t = st1.executeUpdate("...." + s + ")");
//----------------------------------^---
BUT
Instead of using this way, this can cause a syntax error like your case, and can cause an Sql Injection you have to use PreparedStatement.
Upvotes: 1
Reputation:
there is error in your mysql syntax
String query="insert into stdetails (regno,nam,gender) values(?,?,?)";
PreparedStatement preparedStmt2 = con.prepareStatement(query);
preparedStmt2.setInt (1," ");
preparedStmt2.setString (2," ");
preparedStmt2.setString(3, " ");
preparedStmt2.execute();
like this you can add more columns also
Upvotes: 1