• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Connection

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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()?
 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
reply
    Bookmark Topic Watch Topic
  • New Topic