日期:2014-05-16  浏览次数:20916 次

MySQL PreparedStatement 使用注意
String   sql;
PreparedStatement   pStmt=conn.prepareStatement(sql);
pStmt.setShort(1,(short)10)
pStmt.setString(2, "test ");

pStmt.executeUpdate(sql);         //出现Exception

ava.sql.SQLException:   Syntax   error   or   access   violation,     message   from   server:   "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 "

这个问题是由于最后pStmt.executeUpdate是不能带参数的。应该直接用。
pStmt.executeUpdate();