What exactly does Class.forName() does....I know that it loads the driver into the JVM but later, how does that driver gets registered with the DriverManager class??
Also, can anyone explain me the difference between ClassLoader.loadClass() and Class.forName()??
how does that driver gets registered with the DriverManager class??
The javadocs for java.sql.Driver talk about that. It involves calling DriverManager.registerDriver.
can anyone explain me the difference between ClassLoader.loadClass() and Class.forName()??
Have you tried using ClassLoader.loadClass instead of Class.forName to load a JDBC driver? If not, do so; if there is a difference, it should become apparent then.
BTW, one question mark per question is sufficient. [ June 26, 2007: Message edited by: Ulf Dittmer ]
ClassLoader.loadClass ; loadClass is not a static method , its a non static method of class ClassLoader.
Regarding : how does that driver gets registered with the DriverManager class??
Try decompiling any driver class , you will find a static block doing the registration stuff. [ June 26, 2007: Message edited by: Rahul Bhattacharjee ]
I might guess that "static block" is the truly new information here. If you put code in a block like this:
then the JVM runs that code when ... um, you look it up. Anyhow, if it looks magical that you just think about a class with Class.forName() and it gets registered, there's the magic.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Rahul Bhattacharjee
Ranch Hand
Joined: Nov 29, 2005
Posts: 2300
posted
0
static block would get executed when the class gets loaded (creation of instance is not required), so loading a class might be enough for registering a driver.
Originally posted by Jothi Shankar Kumar Sankararaj: By the way how can I decompile a class?
Keep in mind that this is often illegal. E.g., the license for the JDK forbids this. Of course, the JDK class library comes with its own source in a file called "src.zip", so this isn't even necessary.
If it's third-party drivers, then there, too, it shouldn't be necessary. Either they're open source (in which case it's easier to just look at the source), or they're commercial, in which case the license forbids decompilation. [ June 26, 2007: Message edited by: Ulf Dittmer ]
Rahul Bhattacharjee
Ranch Hand
Joined: Nov 29, 2005
Posts: 2300
posted
0
Originally posted by Ulf Dittmer: or they're commercial, in which case the license forbids decompilation. [/QB]
Thanks for this information.I was unaware that some license might forbid decompilation.