javamysqlswingexportrunnable-jar

Exported Runnable Jar - Unable to connect to database


Friends please suggest a solution

I have completed a java swing maven project using eclipse IDE and MySql database in Ubuntu 20.04 OS. Exported the project as Runnable jar (Launch configuration as my main function class and library handling radio button selected is extract required libraries into generated jar).

The runnable jar then, I have opened in Windows 10 OS. By double click the main window opens and I can open only 2 windows from the menu bar of the main window and these two window class are not having sql connection. All other windows are having database connection and are not able to open.

In widows 10 I have installed MySql server 8.0.22 (Using legacy authentication method Retain MySql 5.x Compatibility)and Connector j 8.0.22 and I am able to access my database using Query Browser.

I am using maven dependency of mysql-connector-java 8.0.22 in my Project. And my connection Class is hereunder.`


public class MysqlConnector {
    Connection con=null;
    public static Connection dbConnector() {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306","sarams", "password");
            return con;
    }
        catch (Exception e) {
            return null;
            
        }
             
        }
}     

Solution

  • The problem was solved and it was just a java conflict. Compiled using jdk 11 and tried to run JRE 1.8. removed JRE and installed JDK 11 and the problem was solved.