File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes jdbc and mysql Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "jdbc and mysql" Watch "jdbc and mysql" New topic

jdbc and mysql

Divyajot Ahluwalia
Ranch Hand

Joined: Nov 03, 2000
Posts: 46
can someone pl tell me how to connect to mysql?
what is the driver? procedure to get it and install
what is the code required
Sandeep Jain
Ranch Hand

Joined: Oct 25, 2000
Posts: 124
To connect to the mysql database u hava to download a driver called "" .
For ur query i am writing a small peice code
DriverManager.registerDriver(new Driver());
String s = "jdbc:mysql://";
Connection con = DriverManager.getConnection(s);
Rest of the statement are same .

If u dont have the driver and if u dont get the driver on net mail me i will send u the file
Sandeep Jain

Try and Try Till u succeed<br /> <br />Sandeep Jain
Sandeep Jain
Ranch Hand

Joined: Oct 25, 2000
Posts: 124
I just forgot to mention that
1)first one is the ip address
2) test -> the database name
Sandeep Jain
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Here is the generic connect to database code:

This uses a file called that looks like this:

Customize the file for any database. Here is the example for JDBC-ODBC:

[This message has been edited by Thomas Paul (edited November 21, 2000).]

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

Joined: Feb 03, 2001
Posts: 142
Hi Thomas,
I know that your message was posted a long time ago, but could you email me at to describe how you put the following into a .properties file. I've been trying this myself and have been experiencing some trouble with it. Thanks for your time.

Brian Snyder
Ranch Hand

Joined: Feb 03, 2001
Posts: 142
I actually answered my own question with thanks to long sun. I didn;t realize you had to actually set the properties using a properties file. Thanks!!
Smilidon Sapiens
Ranch Hand

Joined: Nov 02, 2000
Posts: 66
can anybody tell me the function of the line:
if (drivers != null)
System.setProperty("jdbc.drivers", drivers);
Why that line?
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

The JDBC API is designed to run with any complient driver. When you ask JDBC for a connection to a database, the DriverManager needs to know which driver to get it from. It gets this information from the 'jdbc.driver' property stored in the Java System properties. (ie NOT the actual computer properties.)
There are (generally) two ways of defining a driver. The easiest is to call Class.forName("fully qualified driver name"). This makes it the driver's responsibility to register itself with JDBC and life goes on.
The other way is to define the driver name on the command line when executing the program using the -D<name>=<value> option.
(The code above provided by Thomas is equivalent to the first method)
A third method that I hadn't thought of is to simply write the driver name directly to the JVM properties, although I don't see any advantage over the Class.forName() method...
Ken Shamrock
Ranch Hand

Joined: Jan 23, 2002
Posts: 139
if after I compiled that servlet which works with DB, I delete the mysql???.bin copied to jdk1.4, can the Servlet still work? I've tried, it can. So basically this driver is only for compile?

Thanks everyone who helped me
I agree. Here's the link:
subject: jdbc and mysql
It's not a secret anymore!