新接觸一個項目,導入源碼,在本地啟動的時候后台報了一個錯誤:
Could not discover the dialect to use. java.sql.SQLException: Io 異常: The Network Adapter could not establish the connection at java.sql.SQLException: Io 異常: The Network Adapter could not establish the connection at at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112) at at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146) at at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:255) at at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387) at at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:439) at at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165) at at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35) at at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801) at at java.sql.DriverManager.getConnection(DriverManager.java:582) at at java.sql.DriverManager.getConnection(DriverManager.java:185) at at ch.qos.logback.core.db.DriverManagerConnectionSource.getConnection(DriverManagerConnectionSource.java:54) at at ch.qos.logback.core.db.ConnectionSourceBase.discoverConnnectionProperties(ConnectionSourceBase.java:47) at at ch.qos.logback.core.db.DriverManagerConnectionSource.start(DriverManagerConnectionSource.java:38) at at ch.qos.logback.core.joran.action.NestedComplexPropertyIA.end(NestedComplexPropertyIA.java:168) at at ch.qos.logback.core.joran.spi.Interpreter.callEndAction(Interpreter.java:315) at at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:194) at at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:180) at at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:52) at at ch.qos.logback.core.joran.spi.Interpreter.play(Interpreter.java:332) at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:126) at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:93) at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:52) at at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:60) at at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:121) at at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:85) at at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55) at at org.slf4j.LoggerFactory.bind(LoggerFactory.java:121) at at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:111) at at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:268) at at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:241) at at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:156) at at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:132) at at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:272) at at org.mule.context.DefaultMuleContextFactory.<clinit>(DefaultMuleContextFactory.java:36)
首先想到的是是不是數據配置有問題,找到配置數據庫的文件,先檢查服務器IP是否正確,ping一下服務器IP地址,看是否正確,在dos頁面輸入如下指令:
ping 服務器IP
得到的結果如下:
請求超時,意識到這可能是生產環境的數據,在本地啟動沒有操作權限,需要更改為測試環境的數據庫啟動。
如若沒有找到問題所在,后續的分析方法:
1.判斷端口號是否正確,在一般不會有錯誤,但可能使用多個oracle版本,導致端口號不為1521的情況。
進行一下操作:在DOS上鍵入sqlplus,檢查oracle是否開啟,若一切正常,問題仍沒有解決,進行下一步。
2.檢查目標機器是否裝有防火牆,可能是服務器端口號屏蔽而造成的,關閉防火牆后,嘗試重新連接。仍未解決,進行下一步。
3.檢查數據庫監聽是否啟動:下面以現在主流的數據庫ORACLE為例:
重新手動啟動數據庫監聽: 開始 → 運行→ 輸入CMD→ 進入DOS命令提示界面 d:>lsnrctl LSNRCTL> status 或者 LSNRCTL> start
注:可能服務器上有多個監聽,默認lsnrctl start啟動的是 LISTENER這個監聽, 查看其他監聽可以搜索listener.ora這個文件。
看看是否有其他的監聽,如果有,使用lsnrctl start 監聽名字。
# listener.ora Network Configuration File: D:\app\Administrator\product\11.2.0\dbhome_1\network\admin\listener.ora # Generated by Oracle configuration tools. SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME=RS) (SID_NAME = RS) (ORACLE_HOME = D:\app\Administrator\product\11.2.0\dbhome_1) (ENVS = "EXTPROC_DLLS=ONLY:D:\app\Administrator\product\11.2.0\dbhome_1\bin\oraclr11.dll") ) ) LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.12)(PORT = 1521)) ) ) ADR_BASE_LISTENER = D:\app\Administrator