PDA

View Full Version : MYSQL syntax error



phamtranquocviet
14 Mar 2009, 9:35 AM
Hi,

This following codes throw this error, and I can't tell why. Please help. Thanks.

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


connection.setAutoCommit(false);
String sql = "INSERT INTO User (First, Middle, Last, ID, Pass, RecDate, Note) " +
"VALUES (?, ?, ?, ?, ?, ?, ?)";
ps = connection.prepareStatement(sql);
ps.setString(1, mem.getFirst());
ps.setString(2, mem.getMiddle());
ps.setString(3, mem.getLast());
ps.setString(4, generateId());
ps.setString(5, Util.md5(mem.getLast()));
ps.setDate(6, today);
ps.setString(7, "");
ps.addBatch();

ps.execute(sql, Statement.RETURN_GENERATED_KEYS);

phamtranquocviet
14 Mar 2009, 3:36 PM
I solved the issue. Since I called addBatch(), I have to call executeBatch() instead of execute(....).
Thanks.