This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes Connect to MySQL data base Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Connect to MySQL data base" Watch "Connect to MySQL data base" New topic
Author

Connect to MySQL data base

Smilidon Sapiens
Ranch Hand

Joined: Nov 02, 2000
Posts: 66
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

Joined: Nov 02, 2000
Posts: 66
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

Joined: Nov 22, 2008
Posts: 18944
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

Joined: May 05, 2000
Posts: 13974
Make sure that the jar file is in your classpath.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Paul Bailey
Ranch Hand

Joined: Oct 20, 2000
Posts: 91
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

Joined: Oct 20, 2000
Posts: 91
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!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Connect to MySQL data base
 
Similar Threads
Entity Bean that works on Mysql
JSP and MySql
MySql help needs
JDBC drivers
Why my JDBC not working in servlet