!!新手极其容易踩的坑!!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 ‘like ‘%3%’’ at line 1目录标题)
唉,找bug简直要搞死人了,新手小白表示一个空格搞一晚上真的伤不起啊伤不起5555555
报错: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 ‘like ‘%3%’’ at line 1
然后定位到错误应该在sql语句,我是用的eclipse连接的Mysql,这个是我的sql语句:
StringBuffer sb=new StringBuffer(“select * from 客房”);
if(StringUtil.isNotEmpty(room.getRoomId())){
sb.append(“where 客房号 like '%”+room.getRoomId()+"%’");//打空格!!
}
if(StringUtil.isNotEmpty(room.getRoomType())){
sb.append(“where 客房类型 like '%”+room.getRoomType()+"%’");
}
if(StringUtil.isNotEmpty(room.getStatus())){
sb.append(“where 当前状态 like '%”+room.getStatus()+"%’");
}
看似毫无错误,但一运行就报错
最后发现,在where前面还应该有个空格!!
纪念一下
我气死了