views:

33

answers:

2

I get the following error when attempting to connect to the MySQL database on my employer's local server:

Unable to load database driver Details : java.lang.ClassNotFoundException: com.mysql.jdbc.Driver BUILD SUCCESSFUL (total time: 0 seconds)

I think it's pretty clear that this is because I don't have my files set up properly. Only problem is, I don't know what I need, and where it needs to go. Is the Driver a .class file? Where can I download it? Where in my filesystem (ubuntu, fwiw) do I put the file so that "Class.forName("com.mysql.jdbc.Driver").newInstance();" works?

Thanks for all your help, m8s.

+1  A: 

You can download the connector here (the .jar you need is inside the .zip/.tar.gz):

http://dev.mysql.com/downloads/connector/j/

The .jar needs to be in a classpath available to your application.

Lauri Lehtinen
+1  A: 

Yes, it is a .class file that uses a others .class files. You call all these collections of files, a library and in this particular case, the library is also named: "jdbc driver".

These libraries are usually .jar files, so in your case you may try:

http://www.mysql.com/products/connector/j/

To download the MySQL JDBC driver.

You should put it in your classpath

OscarRyz
Thanks guys, looks like I have to wait up to 48 hours for MySQL to provide us with the driver :(. In the meantime, it looks like I can figure out setting up the classpath, but what about the .jar file's physical location? I have read, in various places, that the file should live in the JDK folder, or in the webapps/ROOT folder of Tomcat.
@malenkylizards - If you're using Tomcat 6.x, put the .jar file in the TOMCAT_HOME/lib folder, that will make it available to all of the web apps. If you are using some other server, you'll need to find the location for shared .jar libraries and put it there. Note that you CAN also put it under the WEB-INF/lib folder of any given web app. Why 48 hours though?
Lauri Lehtinen
@Lauri Lehtinen, I couldn't say why it was 48 hours, MySQL wouldn't let me download the drivers until I supplied them with an excessive amount of information, including the company's address. I ended up not using their site, because of course, it was already downloaded, I just wasn't looking in the right place. D'oh!