I am facing a peculiar problem - PreparedStatements and CallableStatements are not getting closed in the backend. I have promptly closed all the statement objects and connection objects after their use. Whereas Statements gets closed perfectly.
This is a sample code I have to used to check the closing of the PreparedStatement.
import java.sql.*;
import java.util.*;
import javax.sql.*;
import javax.naming.*;
import com.ibm.ejs.ns.jndi.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class dbase
{
public static void main(
String arg[])
{
PreparedStatement stmt = null;
try
{
Hashtable ht = new Hashtable();
ht.put(Context.PROVIDER_URL,"iiop://plserver:900");
ht.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.ejs.ns.jndi.CNInitialContextFactory");
Context ct = new InitialContext(ht);
System.out.println(" ater Context creation ");
DataSource ds = (DataSource) ct.lookup("jdbc/DS_Test");
System.out.println(" after look up ");
Connection con = ds.getConnection("temp","temp12");
System.out.println(" after connection " + con);
stmt = con.prepareStatement("select * from test");
ResultSet rs = stmt.executeQuery();
if(rs.next())
System.out.println(" DATAS FETCHED ");
Thread.sleep(10000);
rs.close();
stmt.close();
con.close();
System.out.println("ITS TERMINATED");
Thread.sleep(20000);
System.out.println("AFTER SLEEP");
}catch(Exception e)
{
e.printStackTrace();
}
finally
{
try
{
if(stmt != null)
{
stmt.close();
System.out.println("inside close while ");
}
}
catch(Exception e1)
{
System.out.println(" exception caught from finally " + e1);
}
}
}
}
Please help.
regards,
prasadh