jdbc program works in IDE but not on command line

Answered

Within the IDE my JDBC program works (so apparently mysql is working OK, my code is OK, etc.), but I can't get it to run from the command line. (I'm still a Java newbie.)

1) I've added mysql-connector-java-5.0.8 (apparently the latest from oracle) to my bash shell CLASSPATH

2) I also included the same in the artifact jar

3) My command line is java -jar /full/path/to/myProject.jar (full path)

MANY THANX IN ADVANCE!

0
2 comments

Oops, the error message (from the bash shell) would help: "No suitable driver found".

0

Make sure you have this code that loads the driver:

 try {
  Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
  e.printStackTrace();
}

Sample project:

https://dl.dropboxusercontent.com/u/2752840/FunWithJDBC.zip

0

Please sign in to leave a comment.