check the manual that corresponds to your MySQL server version for the right syntax to use near '=4'

今天在写sql动态查询DOMO时出现如下错误:

Parameter index out of range (1 > number of parameters, which is 0).

检查发现错误发生在22行,代码为:

**ps=con.prepareStatement("select *from tab_stu" + "where 编号 = ?");** 

仔细观察发现是“?”的原因,这里是中文的问号,应该改成英文的“?”

改完后再运行,又出现错误:

check the manual that corresponds to your MySQL server version for the
right syntax to use near ‘= 4’ at line 1

查询得知,mysql语法中where前不能有其它符号,只能是空格,再where前敲个空格后,程序运行正常。

**ps=con.prepareStatement("select *from tab_stu" + " where 编号 = ?");** 

猜你喜欢

转载自blog.csdn.net/qq_35455067/article/details/88616172