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

Connect and Statement objects...

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi,
I'm new to JDBC, I just have two quick questions:
First, What is the difference between using the Class.forName()method, and the System.setProperty()method to register a driver. When would you use one rather than the other, as they seem to do the same thing?
second, What are the advantages / disadvantages of creating one Statement object in the initialization of a JDBC connection and then using this object in all your other methods to execute queries etc, then close it in the close() method of the connection. As opposed to creating a new seperate Statement object in each method which needs one. If you know what I mean?
[This message has been edited by J Carklin (edited June 13, 2001).]
Bjarki Holm
Author
Ranch Hand

Joined: May 25, 2001
Posts: 65
Carklin,
first of all, registering a driver with Class.forName() is a JDBC 1.0 practise, which is now mostly obsolete, with the introdcution of DataSource in JDBC 2.0. I've never registered a driver with System.setProperty(), so I'm not sure how it differs from Class.forName(), if it does so in the first place.
Carklin, if you need more information on using the new features of JDBC 2.0, and especially the JDBC 2.0 optional packages, you can start your search in the JDBC Learning Center at Sun, at http://java.sun.com/products/jdbc/learning.html. There is also a lot of information on this topic in this week's book giveaway (I'm playing a salesman this week, so forgive me if you're shocked ), Professional Java Data.
On the other subject, I don't see the (dis)advantages of using multiple Statement objects - not if they're all closed after usage in the first place - except for the obvious added garbage collection and memory usage.
Regards,

------------------
Bjarki Holm
Author of Professional Java Data


Bjarki Holm
Andrew Shafer
Ranch Hand

Joined: Jan 19, 2001
Posts: 338

With multiple statements, you get no advantage and higher overhead in objects instantiated.
Just say no. . .


!_I_Know_Kung_Fu_!
Anil Vupputuri
Ranch Hand

Joined: Oct 31, 2000
Posts: 527
Originally posted by J Carklin:

First, What is the difference between using the Class.forName()method, and the System.setProperty()method to register a driver. When would you use one rather than the other, as they seem to do the same thing?

Yeah, according to me there is a one reason I know, suppose if we have a requirement of using multiple drivers which are specified in properties file, then use register driver method which registers each driver to be used.
If we have only one driver then Class.forName() is enough to load the driver.
HTH...
Anil

SCJP 1.5, SCEA, ICED (287,484,486)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Connect and Statement objects...