• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between DriverManger.registerDriver() and Class.forName() ?

 
Prabhat Ranjan
Ranch Hand
Posts: 397
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How DriverManager.registerDriver() and Driver Interface is involved in registering the driver.

I only know class.forName(); is used to load the driver.
 
Ram Narayan.M
Ranch Hand
Posts: 247
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For DriverManager.registerDriver(Driver driverClass), instance of the respective Driver has to be explicitly created and should be passed as an argument to this method and registers with the DriverManager...

Class.forName(), Only the Driver class name should be passed... at the background, static block defined in the Driver class will be executed which registers with the DriverManager automatically...


So using Class.forName() reduces the overhead
 
Prabhat Ranjan
Ranch Hand
Posts: 397
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is correct , what i was thinking.

I saw actullay in registerDriver Method of DriverManager class, Drivers info are adding in a vector for registering the driver.

this method is static synchronized in nature.
 
Campbell Ritchie
Sheriff
Posts: 51453
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this thread would sit better on our JDBC forum. Moving.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic