Link to home
Start Free TrialLog in
Avatar of starsystems
starsystems

asked on

What happen if I don't close statement in Java

In Java,  If I close a connection but not close a statement. What will happen? What are the potential risks?
Avatar of Mick Barry
Mick Barry
Flag of Australia image

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.

Avatar of starsystems
starsystems

ASKER

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

ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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?
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

thanks.
didn't I answer your questions?
I feel I have answered and question (and also subsuquent queries)