• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using driver and setting connection

 
david colais
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • 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...
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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.
 
sri ramvaithiyanathan
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic