java.sql.SQLException: ORA-00923: 未找到要求的 FROM 關鍵字

會_飛_的豬 發表於 2020-10-16

Spring Boot 連線資料庫異常

在搭建新專案時 , 連線資料庫出現下面異常:

Druid-ConnectionPool-Create-819680566 [ERROR] com.alibaba.druid.pool.DruidDataSource Line:2469 create connection SQLException, url: jdbc:oracle:thin:@127.0.0.1:1521:odsdb, errorCode 923, state 42000 
java.sql.SQLException: ORA-00923: 未找到要求的 FROM 關鍵字

	at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
	at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
	at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
	at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:745)
	at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:207)
	at oracle.jdbc.driver.T4CStatement.executeForDescribe(T4CStatement.java:801)
	at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1039)
	at oracle.jdbc.driver.T4CStatement.executeMaybeDescribe(T4CStatement.java:841)
	at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1126)
	at oracle.jdbc.driver.OracleStatement.executeQuery(OracleStatement.java:1274)
	at com.alibaba.druid.pool.vendor.OracleValidConnectionChecker.isValidConnection(OracleValidConnectionChecker.java:84)
	at com.alibaba.druid.pool.DruidAbstractDataSource.validateConnection(DruidAbstractDataSource.java:1307)
	at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1588)
	at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2466)

解決方案 :

  1. 檢查SQL 是否正確
  2. 檢視配置檔案 validationQuery 配置是否正確

validationQuery:Druid用來測試連線是否可用的SQL語句,預設值每種資料庫都不相同:
Mysql:SELECT 1;
SQLSERVER:SELECT 1;
ORACLE:SELECT ‘x’ FROM DUAL;
PostGresql:SELECT ‘x’;

validationQuery什麼時候會起作用?

當Druid遇到testWhileIdle,testOnBorrow,testOnReturn時,就會驗證連線的有效性,驗證規則如下:
如果有相關資料庫的ValidConnectionChecker,則使用ValidConnectionChecker驗證(Druid提供常用資料庫的ValidConnectionChecker,包括MSSQLValidConnectionChecker,MySqlValidConnectionChecker,OracleValidConnectionChecker,PGValidConnectionChecker);

個人錯誤資訊總結,僅供參考.