org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [SELECT * FROM

org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [SELECT * FROM DEMO_ORDER WHERE 1=1and order_id = '1']; nested exception is 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 'order_id = '1'' at line 1 
org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:233)
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72) 
......
......
......


这个错误主要sql语句出错了,在自己查找的时候,感觉逻辑没有错误,一直找不到错误。
原来的sql语句如下:
String sql = "select * from demo_order";
sql.append("and order_id = '"+ searchValue +"');


经过仔细研究,将整句话拼接:select * from demo_orderand order_id = '"+ searchValue +"';
错误就变得十分明显了,and前面缺少空格,导致dql语句报错。

你可能感兴趣的:(MySQL数据库)