String query = "INSERT INTO 'registration'.'regg' ('fname','lname','address','gender','email','phone','username','password') VALUES (?,?,?,?,?,?,?,?);" ;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(url, username, password);
pst = conn.prepareStatement(query);
pst.setString(1, txtfname.getText());
pst.setString(2, txtlname.getText());
pst.setString(3, txtadd.getText());
pst.setString(4, cmbGender.getSelectedItem().toString());
pst.setString(5, txtEmail.getText());
pst.setString(6, txtphone.getText());enter code here
pst.setString(7, txtuser.getText());
pst.setString(8, txtpass.getText());
pst.executeUpdate();
JOptionPane.showMessageDialog(null, "Register successfully");
这是错误
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 ''registration'.'regg'
('fname','lname','address','gender','email','phone','usern' at line
最佳答案
你能尝试一下吗
String query = "INSERT INTO regg (fname, lname, address, gender, email, phone, username, password) VALUES (?,?,?,?,?,?,?,?)";
希望这对你有用
关于java - 在 MySql Workbench 中插入数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59414175/