Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Declaring a Driver question

 
Sharon Cowling
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic