aspose file tools*
The moose likes JDBC and the fly likes why class loaders ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "why class loaders ?" Watch "why class loaders ?" New topic
Author

why class loaders ?

schandu999
Greenhorn

Joined: Feb 07, 2002
Posts: 9
The Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
is used load the class run time.
A new Object creation does the same .
Then what is the excat difference between these two.
The JdbcOdbcDriver class has static method where it registers the driver DriverManager.registerDriver(jdbcodbcdriver);
If I can call the same stuff using the object why i need the class loader ?
thanks
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
champak
Welcome to the Java Ranch, we hope you’ll enjoy visiting as a regular however,
your name is not in keeping with our naming policy here at the ranch. Please re-register under an appropriate name as shown in the policy.
Thanks again and we hope to see you around the ranch!!


Dave
Graeme Brown
Ranch Hand

Joined: Oct 13, 2000
Posts: 193
For example, using Class.forName() allows you to load the name of the required driver from a properties file at runtime. The separates the database implementation from the java code.
Also Class.forName() throws ClassNotFoundException allowing you to make your code more robust if the required drivers have not been deployed correctly.
schandu999
Greenhorn

Joined: Feb 07, 2002
Posts: 9
hi Graeme ,
Thanks for the reply , but can u please let me know the difference between the process of class loaders and new object creation ?
Thanks
Champak
Graeme Brown
Ranch Hand

Joined: Oct 13, 2000
Posts: 193
Originally posted by champak:
hi Graeme ,
can u please let me know the difference between the process of class loaders and new object creation ?
Thanks
Champak

In terms of making the driver available there is no difference. As you correctly stated in your original post, it is a requirement for the driver to register itself with the driver manager when it is loaded into memory. The loading can be achieved in any way you like.
However, for the reasons I mentioned in my last post, using Class.forName() is the generally accepted and preferred way of achieving this.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why class loaders ?