MySQLjava.sql.SQLException:Unknown column ‘****‘ in ‘where clause‘错误问题原因以及如何解决?

Posted The Gao

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQLjava.sql.SQLException:Unknown column ‘****‘ in ‘where clause‘错误问题原因以及如何解决?相关的知识,希望对你有一定的参考价值。

错误的原因是因为查询语句使用错误。

比如一个用户表的属性有编号Integer id、用户名String username和密码String password。

当要根据编号id查询user时,id是int类型装箱后的数据类型,本质是数字,可以直接使用查询语句select * from 表名 where id=$id

当要查询用户名username查询user时,username是String类型的数据,所以,应加单引号select * from 表名 where username=$username

以上是关于MySQLjava.sql.SQLException:Unknown column ‘****‘ in ‘where clause‘错误问题原因以及如何解决?的主要内容,如果未能解决你的问题,请参考以下文章