返回顶部

查询避免Unknown column ‘xxx’ in ‘where clause

问题:

单从字面理解,我们很容易得出列名称不存在的结论,

但是,很多时候并不是列名出错造成的,而是由于拼凑sql语句时对字符类型数据没有用引号引起来造成的。

 

例子:

      例如:  String sql="select age from user where name="+xxx+";

              设置name的值为columName,则错误如下:

 

                Unknown column  'xxx′ in ‘where clause’

 

解决步骤:

sql中如果name是整型的倒不会出现什么错误,而如果sql中字符串类型必须要包含在引号内。

所以修改sql为String sql="select age from user where name='"+xxx+"'";

则错误消失。

 参考;http://blog.sina.com.cn/s/blog_6870d1e00100k7fo.html

posted @ 2020-01-15 23:45  fen斗  阅读(582)  评论(0编辑  收藏  举报