目录

java.sql.SQLSyntaxErrorException-ORA-00933-SQL-command-not-properly-ended错误

目录

java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended错误

看下完整的异常

2018-10-19 20:13:34: INFO [http-nio-8080-exec-10] o.s.b.f.x.XmlBeanDefinitionReader XmlBeanDefinitionReader.java:317 - Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
2018-10-19 20:13:34: INFO [http-nio-8080-exec-10] o.s.j.s.SQLErrorCodesFactory SQLErrorCodesFactory.java:127 - SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase, Hana]
2018-10-19 20:13:34: WARN [http-nio-8080-exec-10] c.e.c.w.a.ControllerExceptionAdvice ControllerExceptionAdvice.java:44 - RuntimeException
2018-10-19 20:13:34: WARN [http-nio-8080-exec-10] c.e.c.w.a.ControllerExceptionAdvice ControllerExceptionAdvice.java:45 -
### Error querying database.  Cause: java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended

### The error may exist in class path resource [mapper/StartMapper.xml]
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: SELECT *         FROM start         ORDER BY "last_updated" DESC LIMIT ?
### Cause: java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended

; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended

说下场景,我用的是Mybatis对接MySQL,并且使用了分页插件,一切都是OK的。现在有需求要同时兼容Oracle,切换的时候出现上面异常。

现在直接给出问题原因(我只能说是我问题的答案,至于其它场景引起的这个异常不一定合适)

database:
  type: oracle

mybatis:
  mapper-locations: classpath:mapper/*.xml
  configuration:
    database-id: ${database.type}
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

pagehelper:
  auto-dialect: true
  close-conn: true
  offset-as-page-num: true
  helper-dialect: ${database.type}
  reasonable: true

问题就出在pagehelper的helper-dialect上,这里必须要指定成Oracle。

其实我jar包外(Linux服务器上)的配置application.yml中的配置是oracle,这点没问题的,application-prod.yml中没有这个配置,但是打包的时候项目中的application-prod.yml是之前的代码有这个配置,设置的是mysql。

总之我的这个异常是pagehelper的数据库类型不匹配引起的。