我试图向表中添加详细信息,但它显示了一些 SQL 错误
查询是:
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+"");
错误是
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
最佳答案
您的查询末尾缺少括号 ),因此它应该如下所示:
t = st1.executeUpdate("...." + s + ")");
//----------------------------------^---
但是
而不是使用这种方式,这可能会导致语法错误,如您的情况,并可能导致 Sql Injection你必须使用 PreparedStatement .
关于JAVA jdbc Eclipse SQLException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42665806/