首页 > 解决方案 > JAVA Runnable .JAR File incomplete execution. Eclipse IDE Runs to completion

问题描述

Running into an issue with a JAVA application that I'm hoping someone can provide some clarity to. I have a simple Java Application which is being built in the Eclipse IDE. I have JRE 1.8.0_251 installed on PATH.

My application at a basic level performs the following:

  1. Load a properties file
  2. Connect to a MSSQL Database based on that SQL File (using java.sql.Connection)
  3. Queries some data.
  4. Updates some data.

This all works without issue in Eclipse. However, when I export my file to a runnable .JAR file, it appears to stop after attempting to initialize the database connection. However, it does not throw a SQLException and never returns from the method. I checked my .jar file in 7ZIP to make sure that the SQLJDBC42.jar was packaged in the folder and it was.

The last log line I see when my runnable JAR executes is: Log.info("Connecting to Database...") however, all items run / and are logged in Eclipse execution.

Any ideas? Code below:

 public void ConnectDatabase() { 
                    
        Log.info("Connecting to Database...");
        
        try {
            //Connect to Database and Log success.
            ConnectionInstance = DriverManager.getConnection(connectionURL);
            Log.info("Database Connection Successful.");
            
        } catch (Exception e) {
            Log.info(String.format("ERROR | DATABASE: %s",  e));
            //System.exit(0);
        }             
        
        Log.info("Leaving Database Method.");
        
    } 

标签: javaeclipsejdbcsqljdbc

解决方案


推荐阅读