• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connecting to a MySQL DB

 
J Dunn
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34229
341
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34229
341
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, we have a forum specifically for JDBC questions. I'll move this to it for you.
 
J Dunn
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That will only work if you have a folder called path.
 
J Dunn
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm compiling with the actual path between the home folder and the driver, I just left it out since it wasn't relevant.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic