• 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

How come I need to register driver (Class.forName() method)in JavaEE, but not in JavaSE projects?

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey,

Not long time ago, I was doing some Java SE programming. To make use of JDBC, I would simply put driver in project's build path. And that is how everything worked.

But then I started studying about Servlets & JSPs. Instead of Java project, now I had Dynamic Web Project. I did the same work (put driver inside project's build path) and hoped everything would work. Unfortunately, it didn't.
I found out here that I need to register my driver using Class.forName() method.

My questions looks rather simple => Why I need to register driver for Dynamic Web Project, but not for Java Project?

Thanks in advance!
 
Marshal
Posts: 73022
330
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure. I think that link should have said that the use of Class.forName() is a very old‑fashioned idiom and most people use a driver manager nowadays.
 
Saloon Keeper
Posts: 23774
161
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Class.forName() was a mechanism to force loading of database drivers. It has been obsolete for a very long time now, but people keep replicating it.

A webapp should NOT be using a DriverManager It should be using a Database Connection Pool. Connection Pools define the database context (including the driver) to the webapp server, and that knowledge is not required by the webapp itself.
 
It will give me the powers of the gods. Not bad for a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic