You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version

今下午一连遇到了俩错误, 都是比较低级的 

只能说是基础不到家, 唉。。。。。。。。。。 

String psql = "select * from users where id = ?"; pstmt = conn.prepareStatement(psql); pstmt.setInt(1, id); ResultSet rs = pstmt.executeQuery(psql); 

ResultSet rs = pstmt.executeQuery(psql); 运行【完】这的时候 会抛出一个异常: 

com.mysql.jdbc.exceptions.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 

============================================ 

在解决问题的时候 一直围绕着 “参数”-- ? --求解,但是。。。。 

没有留意 executeQuery () 的用法 

executeQuery  一个是不带参数的, 另一个是带参数的:

二者之间的区别

executeQuery () 是  pstmt 中的方法 

executeQuery (sql)  是继承自stmt中的方法

=============================================

 

 

你可能感兴趣的:(sql,mysql,server,String)