[英]Unable to connect to Oracle database using the JAR file
我正在使用 eclipse 2020 版,並且添加了連接到 Oracle 服務器(如 ojdbc7.jar)所需的所有庫,我的代碼如下所示:
public Connection SetDatabaseConnection() {
writeInLog("Connecting to IRB", 0);
if(openConnection()){
try {
productionPool.setDriverType("thin");
productionPool.setUser(username);
productionPool.setPassword(password);
productionPool.setPortNumber(Integer.parseInt(port));
productionPool.setServerName(IP);
productionPool.setServiceName(serviceName);
productionPool.setURL("jdbc:oracle:thin:@"+ _connStr.substring(_connStr.indexOf(":")+1));
productionPooledConnection = productionPool.getPooledConnection();
if (productionPooledConnection != null) {
//return true;
currentConnection = productionPooledConnection.getConnection();
logger.info("Connected to IRB server");
return currentConnection;
}
} catch (SQLException ex) {
logger.info("Unable to connect to IRB server, SQLException: "+ex.getMessage());
System.out.println(" (IRB-Exception) DB Exception: \n"+ ex);
}
}
}
我的問題是:我可以在 eclipse 中調試或運行應用程序時連接到服務器,但是當我導出 JAR 文件時,應用程序在這一步中停止了。
另外:我打開連接的代碼:
private boolean openConnection(){
try {
productionPool = new OracleConnectionPoolDataSource();
productionPooledConnection = new OraclePooledConnection();
logger.info("openConnection(): Connected to IRB server \n");
return true;
} catch (SQLException e) {
e.printStackTrace();
logger.info("Unable to connect to IRB server , SQLException: "+e.getMessage());
}
logger.info("openConnection(): Unable to connect to IRB server \n");
return false;
}
應用程序從不拋出任何異常,它只在日志文件中寫入此語句: writeInLog("Connecting to IRB", 0);
我找不到發生這種情況的確切原因,但我刪除了導致錯誤 FAT Jar Export: could not find the class-path for ...etc 並再次導入它們的 JAR。 它工作成功。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.