我在添加 4 个 JTextField 中的数据以将它们插入到表 sql 中时遇到问题 但它给了我关于查询的错误
这是代码
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
String connectionUrl = "jdbc:mysql://localhost:3306/admin";
String connectionUser = "root";
String connectionPassword = "123456";
conn = DriverManager.getConnection(connectionUrl, connectionUser, connectionPassword);
stmt = conn.createStatement();
stmt.executeUpdate("INSERT INTO user(id, nom, login, mdp, statut) VALUES ('','"+jTextField2.getText()+ "','" +jTextField4.getText()+"','"+jTextField3.getText()+"','"+jPasswordField1.getText()+"'");
}catch (ClassNotFoundException ex) {
Logger.getLogger(frame.class.getName()).log(Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
Logger.getLogger(frame.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
Logger.getLogger(frame.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(frame.class.getName()).log(Level.SEVERE, null, ex);
}
这是错误:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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
最佳答案
查询中的 VALUES() 缺少结束括号。
stmt.executeUpdate("INSERT INTO user(id, nom, login, mdp, statut) VALUES ('','"+jTextField2.getText()+ "','" +jTextField4.getText()+"','"+jTextField3.getText()+"','"+jPasswordField1.getText()+"')");
关于java - 从 jTextField 到表 sql 的查询插入错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17324917/