File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connecting to a MySQL DB

 
J Dunn
Greenhorn
Posts: 5
  • 0
  • 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: 33694
316
Eclipse IDE Java VI Editor
  • 0
  • 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: 33694
316
Eclipse IDE Java VI Editor
  • 0
  • 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
  • 0
  • 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
Pie
Posts: 47258
52
  • 0
  • 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
  • 0
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic