gpt4 book ai didi

JAVA jdbc Eclipse SQLException

转载 作者:行者123 更新时间:2023-11-29 06:04:23 25 4
gpt4 key购买 nike

我试图向表中添加详细信息,但它显示了一些 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com