Class not found exception for com.mysql.jdbc.Driver not class problem

I have been working on this for several weeks, and now I'm just running in circles. I get a runtime error: "class not found exception in [class] when receiving com.mysql.jdbc.Driver connection".

The connection function is as follows:

/**
 * @return a MySQL connection to the server as specified above 
 */
private static Connection getConnection() {
  Connection con = null;
  try {
    Class.forName("com.mysql.jdbc.Driver");
    con = DriverManager.getConnection(url, username, password);
  } catch (ClassNotFoundException e) {
    System.err.println("class not found exception in [class] while getting connection " + e.getMessage());
  } catch (SQLException e) {
    System.err.println("sql exception in [class] while getting connection " + e.getMessage());
  }
  return con;
} //end getConnection

I installed a $CLASSPATHhundred times a hundred ways, and still no luck. It looks like this:

# echo $CLASSPATH
:/usr/share/java/mysql-connector-java-5.1.13-bin.jar:/usr/share/java/mysql-connector-java-3.0.17-ga-bin.jar:

Both of these files exist and contain the Driver.class file in the right place.

I even tried to import the class into my code before exporting the jar, but this caused a world of other problems.

I am using Eclipse 3.5.2 and the server runs Fedora 13 x86_64

Please, help.

edit: I run the code remotely on my server using the command:

# java -jar program.jar
+3
5

, Eclipse, " Eclipse Run". Menu Run → Run Configuration → project project → Classpath → User Entries → Add Jar...

+4

Eclipse :

  • ""
  • " "
  • "" - " Java"
  • , (, mysql-connector-java-5.1.20.jar).
+4

Apache Tomcat, JDBC- jar (mysql-connector-java-5.0.8-bin.jar) lib Tomcat home \apache-tomcat-6.0.29\lib\.

<tomcat_home>\common\lib\, common, 6.0 .

.

+3

​​: , ClassPath: , eclipse, eclipse . JAR , .

+1

,

( / "" , ).

Java " "

Then check the empty box next to the library that I wanted to include in the jar export. (In my case, it was ojdbc6.jar)

0
source

Source: https://habr.com/ru/post/1777767/


All Articles