The Artima Developer Community
Sponsored Link

Java Answers Forum
Closing Statement

1 reply on 1 page. Most recent reply: Jul 11, 2002 8:35 PM by Singh M.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Nicolas

Posts: 3
Nickname: nico
Registered: Jul, 2002

Closing Statement Posted: Jul 11, 2002 6:28 PM
Reply to this message Reply
Advertisement
Assume I have java code like listed below:
			try {
				Statement stmt = con.createStatement();
				
				String query = "SELECT * FROM table;
				
				ResultSet rs = stmt.executeQuery(query);
							
				while ( rs.next()) {
					String fields1 = rs.getString("field1");
					String fields2 = rs.getString("field2");
			
				}
								
				stmt.close();
			}
			catch ( SQLException sqle ) {
				System.err.println(sqle.getMessage());
			}


And this code is use to run under web. What I like to know is : is that OK if some error accure such as when create the ResultSet object or when reading the table contain. Doesn't it mean that the Statement Object however has created and hasn't close? Is it will consume a lot of server overhead?


Singh M.

Posts: 154
Nickname: ms
Registered: Mar, 2002

Re: Closing Statement Posted: Jul 11, 2002 8:35 PM
Reply to this message Reply
You are right, when a sql exception occurs on executing

ResultSet rs = stmt.executeQuery(query);

stmt object has already been created and will not be closed because exception would have been thrown at the point of executing the query.

So, it is wise to have a finally clause where you close the DB related objects.

Flat View: This topic has 1 reply on 1 page
Topic: Need help: ARRAYS CHANGE DATA IN INSTANTIATED OBJECTS Previous Topic   Next Topic Topic: problem with ODBC data source

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use