0

I am not clear why do we need to use Class.forName("") in JDBC programming. From various materials that I have referred it say that this is needed to load the database drivers; agreed.

My doubt is because of this:

If an application uses say, for example, Hibernate, we never do Class.forName("") to load the classes related to Hibernate and for that matter any other jar on which an application is dependent.

Now, for JDBC programs why specifically we have to load the drivers?

Can anyone please help me understand this?

CuriousMind
  • 8,301
  • 22
  • 65
  • 134
  • 1
    With Hibernate you have to configure which JDBC driver to use and then Hibernate does that `Class.forName("")` for you. – Timothy Truckle May 05 '17 at 10:26
  • Possible duplicate: http://stackoverflow.com/questions/13533071/what-does-forname-method-in-the-class-class-do-when-loading-jdbcodbc-driver – assylias May 05 '17 at 10:27
  • 2
    The call to `Class.forName` has been unnecessary for some 11 years, since introduction of JDBC 4.0. See [this Q&A](http://stackoverflow.com/a/5484254/335858) for details. – Sergey Kalinichenko May 05 '17 at 10:28
  • @TimothyTruckle: My doubt is still same, for an application to use Hibernate to begin with, it never does class.forName("") for hibernate classes. So why this special treatment for JDBC. – CuriousMind May 05 '17 at 10:30
  • Class.forName will give you ability to provide class file at run time in case of if you need some another diver to be used at run time in JDBC – Rahul Rabhadiya May 05 '17 at 10:36

0 Answers0