Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Using driver and setting connection

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,
I am a newbie to jdbc.The problem i am facing is i do not know what to use ie "string value" to load a driver in the Class.forname() method and the String to put in the DriverManager.getConnection() methods.
I have installed mysql server 5.1 and its working fine.I have also set the dsn as "MyDSN" and its driver is mentioned as "MySql ODBC 5.1 Driver".
presently there are 3 databases in db server:mydb,mysql,first.
If i have to use any one of these databases then what should my previously asked values be.
Please help...
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Personally, I would not use a DSN. The JDBC-ODBC bridge is not really for production code.

Have a look at the docs for MySQL Connector/J. This should explain what you need to do.
 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For mysql
Class.forName("com.mysql.jdbc.Driver");

DriverManager.getConnection(jdbc:mysql://host:3306/database_name, "userName", "password");

In host,for localmachine use localhost and for other machine use that machine ipaddress
for example(192.168.4.1)
database_name--the database which you want to establish connection.
userName-->userName for the database
password-->password for the same.

Regards,
Sriram.V
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic