File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Connecting to a MySQL DB Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "Connecting to a MySQL DB" Watch "Connecting to a MySQL DB" New topic
Author

Connecting to a MySQL DB

J Dunn
Greenhorn

Joined: Oct 29, 2008
Posts: 5
It's probably something simple that im missing but I cant figure out how to start the connection. I have the mysql-connector-java-####-bin in the same directory I am running the code from but it generates an error saying class not found on the line with Class.forname() when I try to start up the driver so that I can make a connection.

Any tips would be appreciated, alternatively if you have an idea of an easier way to make the connection I am open to that. I am not attached to doing it this way, I just need to be able to connect to a DB on the same box so that I can add entries and run queries.

Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 26166
    
  66

Welcome to JavaRanch!

You need to explicitly add the jar to the classpath. Being in the same directory isn't enough for Java to find the driver.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 26166
    
  66

Also, we have a forum specifically for JDBC questions. I'll move this to it for you.
J Dunn
Greenhorn

Joined: Oct 29, 2008
Posts: 5
I tried compiling with:

javac -classpath $HOME/path/mysql-connector-java-5.1.6-bin.jar testconnection.java

Which I believe should add it to the class path but it has the same result.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32611
    
    4
That will only work if you have a folder called path.
J Dunn
Greenhorn

Joined: Oct 29, 2008
Posts: 5
I'm compiling with the actual path between the home folder and the driver, I just left it out since it wasn't relevant.
 
I agree. Here's the link: http://jrebel.com/download
 
subject: Connecting to a MySQL DB
 
Similar Threads
Cannot open connection issue
How to retrieve images from mysql database into a portlet
Problem in Java Connection with MySQL in Linux Mandriva.
JDBC in Applets, problems
JDBC, mysql connector/j, face a problem to connect mysql 5.1 and JSE.