• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jdbc and mysql

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sandeep Jain
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just forgot to mention that
the
1)first one is the ip address
2) test -> the database name
------------------
Sandeep Jain
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
can anybody tell me the function of the line:
if (drivers != null)
System.setProperty("jdbc.drivers", drivers);
Why that line?
Thanks!
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic