Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法使用JAR文件连接到Oracle数据库_Java_Database_Oracle - Fatal编程技术网

Java 无法使用JAR文件连接到Oracle数据库

Java 无法使用JAR文件连接到Oracle数据库,java,database,oracle,Java,Database,Oracle,我使用的是eclipse 2020 edition,我添加了连接到Oracle server所需的所有库,如ojdbc7.jar,我的代码如下: public Connection SetDatabaseConnection() { writeInLog("Connecting to IRB", 0); if(openConnection()){ try { produ

我使用的是eclipse 2020 edition,我添加了连接到Oracle server所需的所有库,如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;
    }

应用程序从不抛出它只在日志文件中写入的任何EXCTION语句:writeInLog(“连接到IRB”,0)

我找不到发生这种情况的确切原因,但我删除了导致FAT Jar导出错误的Jar:找不到…etc的类路径并再次导入它们。它成功运行。

您是否也可以添加stacktrace?在导出jar文件之后,可能是ojdbc7.jar不在类路径上吗?这会弄乱日志记录。您没有将“ex.getMessage()”连接到对象,而是逐字地传递异常,并让日志框架对其进行排序。这样你就可以叠加痕迹、因果链等,你就可以扔掉90%的有用信息。它可能是
logger.info(“blabla”,ex)当我提取JAR文件时,我选择选项“将所需库提取到生成的JAR中”。此外,ojdbc7.jar位于Java构建路径中@rzwitserroot问题是它没有给我任何异常,JAR文件只是存在。正如您所看到的,我在日志文件中写入了任何可能引发异常但从未发生的情况。正如我在问题中所说,它在语句writeInLog(“连接到IRB”,0)中突然停止;这是日志文件中的最后一行!!该应用程序在eclipse内部调试或运行时运行良好,但从未显式工作!!