aspose file tools*
The moose likes JDBC 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
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Using driver and setting connection" Watch "Using driver and setting connection" New topic
Author

Using driver and setting connection

david colais
Greenhorn

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
Bartender

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
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


For java examples,ebooks,interview questions,visit this blog
http://periodicupdates.blogspot.com/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using driver and setting connection