起初,数据库配置为:
datasource: master: url: jdbc:postgresql://ip:5432/databaseName username: ** password: ** driver-class-name: org.postgresql.Driver
当我为项目新增Oracle数据库的连接时,报错如下:
2022-11-19 20:54:48.602 [Druid-ConnectionPool-Create-1602711561] ERROR com.alibaba.druid.pool.DruidDataSource:2699 - create connection SQLException, url: jdbc:oracle:thin:@ip:1521/**, errorCode 923, state 42000 java.sql.SQLSyntaxErrorException: ORA-00923: 未找到要求的 FROM 关键字
问题原因:
druid的数据库配置validationQuery的属性值出错,对于不同的数据库,validationQuery的值是不同的。druid通过validationQuery来判断数据库联通性的,所以validationQuery的值是在当前配置数据库中执行查询,返回不为空数据的一句sql。
DataBase | validationQuery |
hsqldb | select 1 from INFORMATION_SCHEMA.SYSTEM_USERS |
Oracle | select 1 from dual |
DB2 | select 1 from sysibm.sysdummy1 |
MySql | select 1 |
Microsoft SqlServer | select1 |
postgresql | select version() |
ingres | select 1 |
derby | values 1 |
H2 | select 1 |
解决办法:
datasource: master: url: jdbc:postgresql://**:5432/db20181301?currentSchema=** username: ** password: ** driver-class-name: org.postgresql.Driver druid: validationQuery: select 1 # 多数据源配置 slave: url: jdbc:oracle:thin:@ip:1521/** username: ** password: ** driver-class-name: oracle.jdbc.OracleDriver druid: validationQuery: select 1 from dual
标签:jdbc,validationQuery,数据源,数据库,druid,errorCode,postgresql,select From: https://www.cnblogs.com/BeenTogether/p/16907073.html