• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Is there a way to get/import the driver class from a jar file instead of writing Class.forName()?

 
Ranch Hand
Posts: 75
Chrome Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code below shows the database interaction.
Actually I want to know is there a way to get/import the driver class from a jar file instead of writing Class.forName(driverDetails)? I was asked this question by one of my superiors.




--Thank you
-Rajeev
 
Master Rancher
Posts: 4663
49
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the driver is a type 4 one (which all the main ones are these days) then the DriverManager itself will find and load the class without the need for Class.forName.
 
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need that line of code at all.
This method of loading the driver class explicitly was deprecated a long time back - like a decade ago.
If the driver JAR contains a driver service entry under its META-INF/services/, the driver class gets loaded automatically by class loader.
Have a look at DriverManager's javadoc for an explanation.
    Bookmark Topic Watch Topic
  • New Topic