gpt4 book ai didi

SQL 数据库连接中的 java.sql.SQLSyntaxErrorException

转载 作者:行者123 更新时间:2023-11-29 06:42:49 24 4
gpt4 key购买 nike

这是我的代码。当我运行它时,出现错误:

java.sql.SQLSyntaxErrorException: 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

有人可以帮我吗?

form_()
{
setSize(265,500);
setVisible(true);
setLayout(new FlowLayout());
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(l4);
add(t5);
add(l5);
add(t4);
add(b);
b.addActionListener(this);

}

@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==b) {
int x = 0;
String s1 = t1.getText();
String s2 = t2.getText();
String s3 = t3.getText();
char[] c = t5.getPassword();
String s5 = new String(c);
String s4 = t4.getText();


try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "******", "********");

PreparedStatement ps = con.prepareStatement("INSERT INTO reg1 values(?,?,?,?,?");
ps.setString(1, s1);
ps.setString(2, s2);
ps.setString(3, s3);
ps.setString(4, s4);
ps.setString(5, s5);
int rs = ps.executeUpdate();
x++;
if(x>0)
{
JOptionPane.showMessageDialog(b,"Data saved Successfully");
}
} catch (Exception ex) {
System.out.println(ex);
}
}
}
}

最佳答案

con.prepareStatement("INSERT INTO reg1 value(?,?,?,?,?"); 这是你的代码中的错误。你应该这样尝试 con.prepareStatement("INSERT INTO reg1 values(?"); ,?,?,?,?)");

关于SQL 数据库连接中的 java.sql.SQLSyntaxErrorException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50832214/

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