wood burning stoves 2.0*
The moose likes JDBC 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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "jdbc and mysql" Watch "jdbc and mysql" New topic
Author

jdbc and mysql

Divyajot Ahluwalia
Ranch Hand

Joined: Nov 03, 2000
Posts: 46
hi,
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
thanks
Sandeep Jain
Ranch Hand

Joined: Oct 25, 2000
Posts: 124
Hi,
To connect to the mysql database u hava to download a driver called "org.gjt.mm.mysql.Driver" .
For ur query i am writing a small peice code
DriverManager.registerDriver(new Driver());
String s = "jdbc:mysql://197.100.0.191:3306/test";
Class.forName("org.gjt.mm.mysql.Driver");
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
the
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 db.properties that looks like this:

Customize the db.properties 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 snydb@home.com 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
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
Hi,
can anybody tell me the function of the line:
if (drivers != null)
System.setProperty("jdbc.drivers", drivers);
Why that line?
Thanks!
David O'Meara
Rancher

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...
DOM
Ken Shamrock
Ranch Hand

Joined: Jan 23, 2002
Posts: 139
Hi,
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
 
Consider Paul's rocket mass heater.
 
subject: jdbc and mysql
 
Similar Threads
What is mysql ports ?
WA #1.....word association
Advice of database type is needed
getting last row
Using datasource in netbeans to get connection