This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes JDBC and the fly likes Driver problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Driver problem" Watch "Driver problem" New topic
Author

Driver problem

kedar parundekar
Ranch Hand

Joined: May 10, 2006
Posts: 40
import java.sql.*;
class Jdbc1
{
public static void main(String[] args) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// to load driver Type1
System.out.println("Got Driver");
Connection con=DriverManager.getConnection
("jdbcdbc:mydsn","scott","tiger");
// for connection, mydsn is dsn , java is username, java is password
System.out.println("Got Connection");


Class.forName("oracle.jdbc.driver.OracleDriver");
// Type 4 Driver
Connection con = DriverManager.getConnection
("jdbcracle:thin:@dbs:1521rcl","scott","tiger");

System.out.println("Driver Loaded");

System.out.println("Connection received");

Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("Select * from emp");

while(rs.next())
{
System.out.println(rs.getString(1));
System.out.println(rs.getString(2));

}
rs.close();
con.close();
stmt.close();

}
}

Q ) If i am using Type1 as well as Type 4 Driver in my java application
which will be loaded first?
With the help of which Driver connection is establish?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39576
    
  27
You can have as many drivers in a program as you like. They're loaded by the Class.forName statement, so whichever of those comes first, gets loaded first. That shouldn't matter, though, because they're independent of each other.

The driver to be used is determined by the JDBC URL used in the getConnection call.


Ping & DNS - updated with new look and Ping home screen widget
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Driver problem
 
Similar Threads
Stoared procedure & Type 4 driver
types of drivers
How To work With JDBC Type 2 Driver
Type 4
JDBC Error