1. I've installed MySql on my Linux box + tools (MySql Admin tool, Workbench, Query browser)
2. Created the following MySql database account:
Mysql user............: root
Mysql password.....: root
Mysql host.............: localhost
Mysql port.............: 3306 (default)
This user has been granted right to Schema/ table called "test"
2. I've installed the official MySql JDBC driver in.. /usr/share/data
3. I've set the %CLASSPATH% to....................... /usr/share/java
4. Complided the following code without errors
5. When running this code via java JdbcExample2<enter> I get the following output: Exception: com.mysql.jdbc.Driver
6. It looks like the program can not find the JDBC driver.. am i correct?
- What am I missing in this jdbc_example?
- How can I find out WHAT is the cause of the exception
- Which java code do i need to add to gain more insight in what is wrong
(is it a java error, mysql server configuration / user_permissions error)
Thanks for helping me with this "vague" exception:
This error keeps occuring..:
- without the MySql database daemon running
- with the MySql database daemon running
- without a valid userid & password
- with a valid userid & password
Paul Sturrock wrote:Hard to say. Can you change you code to log the stack trace and post it?
Thanks for answering Paul.. I already found the answer by digging deeper into the error myself. Here is what happend:
Location of the MySql-JDBC driver:
A - current directory (just to be sure)
B - /usr/share/java/mysql-connector-java-5.1.13-bin.jar
1. When I first started the program like this
java MySqlLoadDriver<enter> I got this error -> Exception: com.mysql.jdbc.Driver
2. When i added the -cp (classpath) to startup parameters
java -cp /usr/share/java/mysql-connector-java-5.1.13-bin.jar MySqlLoadDriver I got this error:
Exception in thread "main" java.lang.NoClassDefFoundError: MySqlLoadDriver
Caused by: java.lang.ClassNotFoundException: MySqlLoadDriver
at java.security.AccessController.doPrivileged(Native Method)
Could not find the main class: MySqlLoadDriver. Program will exit.
3. Then i added the CURRENT DIRECTORY to the -cp (classpath) like this:
java -cp .:/usr/share/java/mysql-connector-java-5.1.13-bin.jar MySqlLoadDriver MySQL JDBC driver loaded ok.
What was the problem? (an the cause of the error) 1. The JVM did find its way to my own .class file..... (and could not find the MySql jdbc driver)
2. The JVM did find the MySql jdbc driver .............. (and could not load my own .class file)
3. The JVM found both - via the right (and complete) classpath
Thanks fro the motivation Paul!
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com