File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Declaring a Driver question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Declaring a Driver question" Watch "Declaring a Driver question" New topic
Author

Declaring a Driver question

Sharon Cowling
Greenhorn

Joined: Feb 09, 2002
Posts: 18
Hi, currently in my code I have the following:
Driver myDriver = (Driver)Class.forName(postgresql_DRIVER).newInstance();
But I read somewhere that it is not a good idea to instantiate a new instance like that, that it is better to just do the following:
Class.forName(postgresql_DRIVER);
And this does work in my code, can somebody explain to me why it works, and why it should be done this way?
An explanation or a point in the right direction to some documentation would be most appreciated.
Thanks,
Sharon.
Jyothi Lature
Ranch Hand

Joined: Oct 31, 2001
Posts: 60
Hi Sharon,

As far as i know, Class.forName() will return an object of the class that is supplies as an argument for this method.
I hope the following links would throw more light to your question:
http://www.javaworld.com/javaworld/javaqa/2001-04/02-qa-0413-four.html
and
http://www.javageeks.com/Papers/ClassForName/ClassForName.pdf
Happy coding,
Jyothi


Jyothi<br />Sun Certified Java Programmer<br />Brainbench Certified for Javascript
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Declaring a Driver question