PreparedStatment ps = null;
public void executeQueries(){
try{
ps = conn.prepareStatement(Query1);
// Execute Query1 here and do the processing.
ps = conn.prepareStatement(Query2);
// Execute Query2 here and do the processing.
//... more queries
}catch(){}
finally{
ps.close(); // At this point would the caching of queries in DB be lost?
}
}
In my Application, I call the method executeQueries()
frequently.
My question is, If I close the PreparedStatement
in the finally block inside the method (that I use frequently), would the database system remove the caching? If YES, can I make a global PreparedStatement
for the entire application as there are loads of JAVA CLASSES in my application that query the database.
Thank you!
Update : The question has been marked duplicate but the linked thread does not answer my question at all. AFAIK, the database system stores the executed queries in the cache memory. It also stores their execution plan. This is where PreparedStatement
perfoms better than Statement
. However, I am not very sure if the information related to the query is removed once the PreparedStatement
is closed.