• 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

Class.forName()

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
any one can explain the exact need of Class.forName().
I know that i'll load jdbc driver if it is not loaded earlier. Other than this, is there any thing to say.

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


You can get detail description of class.forName(...) in Sun offical Documentation .

class.forName(....) is used to Load the specified class in to JVM.
Java Sun Documentation
 
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Praveen palukuri:
hi,
any one can explain the exact need of Class.forName().
I know that i'll load jdbc driver if it is not loaded earlier. Other than this, is there any thing to say.

Thank you.



That's pretty much all there is to it.

When a JDBC driver is loaded by Class.forName(), a static initialization block will cause it to register itself with DriverManager. After that, even if the class is explicitly unloaded, the driver is still available via the DriveManager.getConnection() method (which would force reloading of the class).

Class.forName() is used rather than the normal Java compilation to allow for programs to be compiled and built that don't know at compile-time which database they will be used with, and therefore don't know which JDBC driver is required.
 
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dynamic class loading is nice. Whether you use it for JDBC or something else it really can make your application flexibly to load concrete implementations of known interfaces at run time.
 
Just the other day, I was thinking ... about this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic