![尝试执行PreparedStatement时发生MySQLSyntaxErrorException [重复],第1张 尝试执行PreparedStatement时发生MySQLSyntaxErrorException [重复],第1张](/aiimages/%E5%B0%9D%E8%AF%95%E6%89%A7%E8%A1%8CPreparedStatement%E6%97%B6%E5%8F%91%E7%94%9FMySQLSyntaxErrorException+%5B%E9%87%8D%E5%A4%8D%5D.png)
试试这个,这应该工作:
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字符串。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)