我使用的是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;
    }

应用程序永远不会抛出任何异常,它只会在以下语句中写入日志文件:writIng(“ Connecting to IRB”,0);