File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Declaring a Driver question

Sharon Cowling

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:
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.
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:
Happy coding,

Jyothi<br />Sun Certified Java Programmer<br />Brainbench Certified for Javascript
I agree. Here's the link:
subject: Declaring a Driver question
It's not a secret anymore!