2
我不断收到以下错误。无法识别以下函数中的SQL语法错误:导致例外
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 '= 3' at line 1
我通过我的整个代码去了,只有它被称为在这个时间点2个SQL函数,能够引起这种错误的:
读
public void Read (String userName) /*have checked validity*/ try { con = getConnection(); PreparedStatement pstmt = con.prepareStatement("SELECT * FROM " + tableName + " WHERE userName=?"); pstmt.setString(1,userName); ResultSet rs = pstmt.executeQuery(); User user; PrintQuery(rs); rs.close(); pstmt.close(); releaseConnection(con); return user; }
GetItem
public void getItem(int userid) /*have checked validity*/ try { con = getConnection(); Statement stmt = con.createStatement(); PreparedStatement pstmt = con.prepareStatement("SELECT * FROM " + tableName +"WHERE UserId=?"); pstmt.setInt(1,userid); rs = pstmt.executeQuery(); PrintQuery(rs); stmt.close(); releaseConnection(con); }
我被困在这些小时现在,我无法解决它。我有双重检查,看看这些参数是否为空等,他们不是。事实上,它们都很好地存在于数据库中。我无法弄清楚我哪里出错了。任何帮助都感激不尽。
谢谢你这么多的拼接过程中缺少一个额外的空间!这解决了我的问题,因为我花了2个小时的时间:(欢迎您提供: – 2013-03-13 01:52:38
':D'很有帮助。 – 2013-03-13 01:53:54