aspose file tools*
The moose likes JDBC and the fly likes Connector/J driver error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Connector/J driver error" Watch "Connector/J driver error" New topic
Author

Connector/J driver error

Keith Wegner
Greenhorn

Joined: Jan 21, 2009
Posts: 10
I hate to ask such a simple question on this board, but I'm not seeing this one...

I'm running 64-bit Vista
Eclipse Version 3.4.1, installed to C:\Program Files (x86)\eclipse
Java JDK is installed to C:\jdk1.6.0_12
Connector/J is installed to C:\mysql-connector-java-5.0.8\mysql-connector-java-5.0.8

CLASSPATH=.;C:\apache-tomcat-5.5.17\common\lib\servlet-api.jar;C:\apache-tomcat-5.5.17\common\lib\jsp-api.jar;C:\Servlets+JSP;..;..\..;C:\apache-tomcat-5.5.27\apache-tomcat-5.5.27\common\lib\servlet-api.jar;C:\apache-tomcat-5.5.27\apache-tomcat-5.5.27\common\lib\jsp-api.jar;C:\Users\kwegner83\Servlets+JSP;C:\mysql-connector-java-5.0.8\mysql-connector-java-5.0.8\mysql-connector-java-5.0.8-bin.jar;C:\Users\kwegner83\workspace\

JAVA_HOME=C:\jdk1.6.0_12

Trying to run the following code displays Driver not loaded => java.lang.ClassNotFoundException: com.mysql.jdbc.Driver to the console:

import java.sql.*;
public class DBTest {
public static void main(String[] args)
{
try
{ Class.forName("com.mysql.jdbc.Driver");
}
catch(ClassNotFoundException e)
{
System.out.println("Driver not loaded => " + e);
System.exit(1);
}
}
}

What's going on here?
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2516
    
  10

Add the Connector/J jar to your project classpath in Eclipse.


OCUP UML fundamental and ITIL foundation
youtube channel
Dhruva Mistry
Ranch Hand

Joined: Nov 21, 2008
Posts: 67

ya.....and it should be in the <project name> folder like all supporting jar files resides


Dhruva
Hector Tenedero
Ranch Hand

Joined: Oct 13, 2008
Posts: 31
Add the Connector / J to the project's build path. It's usually found in the Project menu ( alt+p )
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2516
    
  10

dhruva mistry wrote:ya.....and it should be in the &lt;project name&gt; folder like all supporting jar files resides
No.
Keith Wegner
Greenhorn

Joined: Jan 21, 2009
Posts: 10
Jan Cumps wrote:Add the Connector/J jar to your project classpath in Eclipse.


It is in the CLASSPATH already:

C:\mysql-connector-java-5.0.8\mysql-connector-java-5.0.8\mysql-connector-java-5.0.8-bin.jar;

<EDIT> Actually, I'm not sure how to add it to the project classpath. Can you explain?</EDIT>
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2516
    
  10

Eclipse does not use your classpath when compiling / running your project.

from https://eclipse-tutorial.dev.java.net/eclipse-tutorial/part1.html

Right-click on the project and select "Properties". Go to the "Libraries" tab in "Java Build Path":
Click on "Add (external) JARs..." ...
Keith Wegner
Greenhorn

Joined: Jan 21, 2009
Posts: 10
Jan Cumps wrote:Eclipse does not use your classpath when compiling / running your project.

from https://eclipse-tutorial.dev.java.net/eclipse-tutorial/part1.html

Right-click on the project and select "Properties". Go to the "Libraries" tab in "Java Build Path":
Click on "Add (external) JARs..." ...


I should have also mentioned that I tried adding the connector/j's bin file into my JAVA_HOME path.

I'll try this, though. Thanks.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
The JAVA_HOME environment variable should point to the root folder of the JDK.
The CLASSPATH environment variable is in fact only and only used when you execute java.exe or javac.exe without the -cp, -classpath or -jar arguments.
Keith Wegner
Greenhorn

Joined: Jan 21, 2009
Posts: 10
Bauke Scholtz wrote:The JAVA_HOME environment variable should point to the root folder of the JDK.
The CLASSPATH environment variable is in fact only and only used when you execute java.exe or javac.exe without the -cp, -classpath or -jar arguments.

My JAVA_HOME is pointing there.

Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Which is not the root cause of the problem by the way.

You said that you added the JAR file to the JAVA_HOME, which makes completely no sense. I just wanted to rectify that.
Keith Wegner
Greenhorn

Joined: Jan 21, 2009
Posts: 10
Bauke Scholtz wrote:Which is not the root cause of the problem by the way.

You said that you added the JAR file to the JAVA_HOME, which makes completely no sense. I just wanted to rectify that.

I agree that it makes no sense - I found the idea here:

http://www.stardeveloper.com/articles/display.html?article=2003090201&page=4

"Among the extracted files will be a JAR file with a name like 'mysql-connector-java-3.0.8-stable-bin.jar'. Copy this file to your %JAVA_HOME%/jre/lib/ext folder which on my system happens to be D:\j2sdk1.4.2\jre\lib\ext>.

You should also add the complete path to this JAR file in your CLASSPATH environment variable. ..."
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Ough, things get more worse. Physically placing the JAR file somewhere in the /lib of the JDK is really a bad practice. You shouldn't let your application depend that much on the JDK used. Also, if you have done that, then specifying its path in the classpath either would make completely no sense (simply because the JDK's lib folder is by default already covered by the classpath!).

As pointed out by others, just add it as external library in the build path of your Eclipse project. That's all. There is really no need to do all that nasty stuff outside the IDE.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Connector/J driver error