Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connect to MySQL data base

 
Smilidon Sapiens
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I installed MySQL and copied the "mm.mysql-2.0.4-bin.jar.zip" renamed in "mm.mysql-2.0.4-bin.jar" to my ext/lib folder.
How can I connect to the MySql database ? What package must I import? Please help !
Thanks...
 
Smilidon Sapiens
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have it:
try
{
// The newInstance() call is a work around for some
// broken Java implementations
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
}
catch (Exception E)
{
System.err.println("Unable to load driver.");
E.printStackTrace();
}
try
{
Connection C = DriverManager.getConnection("jdbc:mysql://localhost/mysql?user=&password=");
// Do something with the Connection
}
catch (SQLException E)
{
System.out.println("SQLException: " + E.getMessage());
System.out.println("SQLState: " + E.getSQLState());
System.out.println("VendorError: " + E.getErrorCode());
}
Thanks
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just did this last night and I was able to connect to mySQL with the very same driver using
What kind of problem did you encounter when you first tried it this way?
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure that the jar file is in your classpath.
 
Paul Bailey
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Thomas Paul:
Make sure that the jar file is in your classpath.

How do you do this? I'm using win 2000 and trying to use the example in the cattle drive. I'm using the following line:
java -cp C:\Development\mm_mysql-2_0_4-src.jar; Test
but it still gives me
java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver
 
Paul Bailey
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, so it turns out that one may need to unzip the mm.jar because it contains a jar. So unzip it, and put it in an appropriate file structure (org/gjt/[put mm here]) and then add the jar at that path to your CLASSPATH. what a pain!!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic