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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?
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
> rs.getStatement().close();
> Does the statement close immediately?
yes
ASKER
thanks.
didn't I answer your questions?
I feel I have answered and question (and also subsuquent queries)
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.