数据库模糊查询语句报错

数据库查询语句报错了,不知道是哪个部分错了
代码片:

                con = DBUtil.getConnection();
                System.out.println("select * from group where member like '%"+email+"%'");
                System.out.println("select * from group where member = "+email+"");
                pst = con.prepareStatement("select * from group where member like '%"+email+"%'");
                ResultSet rs = pst.executeQuery();

控制台报错信息:

 select * from group where member like '%989@qq.com%'
select * from group where member = 989@qq.com
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 'group where member like '%989@qq.com%'' at line 1

3个回答

group是关键字,需要转义。如果是sql server,用[],如果是mysql,用

 ``

`

LoveRestart
理强 谢谢,是这个原因,当初建表的时候有问题
大约 4 年之前 回复

希望有用

MySql 模糊查询

LoveRestart
理强 谢谢,原因已经找到了 0.0
大约 4 年之前 回复

你把sql语句复制到数据库中试一遍不就知道了。。。。。

LoveRestart
理强 谢谢,原因已经找到了 0.0
大约 4 年之前 回复
立即提问
相关内容推荐