如何从输入到JTextField的数据中生成sql insert string

时间:2018-04-17 20:10:29

标签: java mysql sql user-interface

我有一些问题让插入字符串工作它给我一个语法错误,但无法弄清楚为什么,任何帮助?

String sql = "INSERT INTO user VALUES ('"+ jtfEmailAddr.getText()+"'," + 
             "'"+ jtfPassword2.getText() + "'," + 
             "'"+ jtfFName.getText() +"','" + jtfSurname.getText() +"')" +
             "ON DUPLICATE KEY UPDATE password='" + jtfPassword2.getText() + "'"+ `enter code here`
             "firstname='" + jtfFName.getText() + "'," +
             "lastname='" + jtfSurname.getText() + "'";
database.insertIntoDatabase(sql);

ERROR:

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 'rr'nn)' at line 1

字母rr nn对于测试目的而言只是随机的

1 个答案:

答案 0 :(得分:0)

enter image description here

尝试在那里添加逗号'',“ 没有更多的信息是我看错的部分 (当然除了“在这里输入代码”......)