[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

What happen if I don't close statement in Java

Posted on 2009-02-22
9
Medium Priority
?
582 Views
Last Modified: 2012-05-06
In Java,  If I close a connection but not close a statement. What will happen? What are the potential risks?
0
Comment
Question by:starsystems
  • 5
  • 3
8 Comments
 
LVL 92

Expert Comment

by:objects
ID: 23708296
thats fine if you are not using a connection pool, closing the connection will close all the statements.
if you are using a connection pool however it is a problem as the close does not necessarily close the connection, it just returns it to the pool.

0
 

Author Comment

by:starsystems
ID: 23708633
I use connection pool, are there any potential risks if I close or not close statement. Can you explain more clearly?

0
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 23708823
if you don't close your statements then the resources used by them cannot be freed, so yes you should close them.
If you don't close your connections then they do not get returned to the pool.

0
Automating Your MSP Business

The road to profitability.
Delivering superior services is key to ensuring customer satisfaction and the consequent long-term relationships that enable MSPs to lock in predictable, recurring revenue. What's the best way to deliver superior service? One word: automation.

 

Author Comment

by:starsystems
ID: 23709110
First, I use the statement like a local variable in my function. Follow me, when my function end, the local variable will destroyed. Can you explain me more?

Second, can I use the following code:

//ResultSet rs
rs.getStatement().close();

Does the statement close immediately?
0
 
LVL 92

Expert Comment

by:objects
ID: 23709139
when the var goes out of scope that only makes it available to be cleaned up, it does not guarantee that the resources are freed.

> rs.getStatement().close();
> Does the statement close immediately?

yes

0
 

Author Comment

by:starsystems
ID: 23709439
thanks.
0
 
LVL 92

Expert Comment

by:objects
ID: 25331365
didn't I answer your questions?
0
 
LVL 92

Expert Comment

by:objects
ID: 25331614
I feel I have answered and question (and also subsuquent queries)
0

Featured Post

Put Machine Learning to Work--Protect Your Clients

Machine learning means Smarter Cybersecurity™ Solutions.
As technology continues to advance, managing and analyzing massive data sets just can’t be accomplished by humans alone. It requires huge amounts of memory and storage, as well as high-speed processing of the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If I have to fix slow responding website my first thoughts are server side optimizations: the database may not be optimized or caching is not enabled, or things like that. We often overlook another major part of our web application: the client. We o…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…
Suggested Courses
Course of the Month19 days, 9 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question