wood burning stoves 2.0*
The moose likes JDBC and the fly likes Connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Connection" Watch "Connection" New topic
Author

Connection

Vallabhaneni Suresh Kumar
Ranch Hand

Joined: Mar 01, 2004
Posts: 68
We had Driver interface and had connect() method in it to establish connections. But why do we prefer to get connection by using DriverManager class getConnection() method? I refer so many books all of them are using DriverManager class.

Thank You
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by Vallabhaneni Suresh Kumar:
We had Driver interface and had connect() method in it to establish connections. But why do we prefer to get connection by using DriverManager class getConnection() method? I refer so many books all of them are using DriverManager class.


So, have you tried to get the connection from Driver.connect()?
Makarand Parab
Ranch Hand

Joined: Dec 10, 2004
Posts: 121
Hi
Okay here is the answer.
When u say Class.forName("oracle.driver.OracleDriver");
Class.forName gets executed. it loads the class "OracleDriver".
In class OracleDriver, there is a static block which gets executed as stated below

public class OracleDriver
{
OracleDriver orDriver = null ;

static
{
if(orDriver == null)
{
//loads and creates a new object if it does
not exist
OracleDriver orDriver = new OracleDriver ();
//then it registers with the Driver Manager using
DriverManager.registerDriver(orDriver);
// this is a static method check
the DriverManager API
}
}
}

Since ur Driver is register with DriverManager, u call DriverManager.getConnection();
If u ur using classes12.jar, check the OracleDriver.class file. Open it and see the code.

Let me know if it makes send 2 you.

Regards
Makarand Parab
Srinivasa Kadiyala
Ranch Hand

Joined: Jun 10, 2004
Posts: 237
Hi..

It is better to use DataSource class that using DriverManager.

You may please refer to the following link...
http://www.oracle.com/technology/tech/java/sqlj_jdbc/htdocs/jdbc_faq.htm#01_02

They will answer your most of the questions.

Good luck...


Srini
 
Don't get me started about those stupid light bulbs.
 
subject: Connection
 
Similar Threads
Iimplemenatation classes of Connection,Statement,PrepareStatement,CallabaleStatement?
Servlets
An urgent doubt
Loading the driver
DriverManager vs DataSource