试试这个,这应该工作:
try { connection.setAutoCommit(true); String sql = "insert into testtable values(?,?)"; PreparedStatement statement = connection.prepareStatement(sql); statement.setInt(1, userId); statement.setString(2, userName); saveStatus = statement.execute(); } catch (SQLException e) { e.printStackTrace(); } return saveStatus;}PreparedStatement是预编译的语句。您不必在执行时提供sql字符串。


![尝试执行PreparedStatement时发生MySQLSyntaxErrorException [重复] 尝试执行PreparedStatement时发生MySQLSyntaxErrorException [重复]](http://www.mshxw.com/aiimages/31/421237.png)
