The moose likes JDBC and Relational Databases and the fly likes Using driver and setting connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Using driver and setting connection" Watch "Using driver and setting connection" New topic

Using driver and setting connection

david colais

Joined: Nov 15, 2010
Posts: 29
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...
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

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.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
sri ramvaithiyanathan
Ranch Hand

Joined: Nov 20, 2010
Posts: 109
For mysql

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(
database_name--the database which you want to establish connection.
userName-->userName for the database
password-->password for the same.


For java examples,ebooks,interview questions,visit this blog
I agree. Here's the link:
subject: Using driver and setting connection
It's not a secret anymore!