lauritspetersen
Programmer
Hi
I have a problem with giving back connections to a connectionpool. I suspect the problem to be within the code. I have defined an init method and a destroy method but after two weeks or so the common resource exception occurs. Please take a look at the code and tell me what might be wrong.
private Connection connection;
private Statement statement;
private Context ctx;
public void init(ServletConfig config) throws ServletException
{
super.init(config);
try
{
ctx = new InitialContext();
Object o = ctx.lookup("defaultPool"
DataSource ds = (DataSource) PortableRemoteObject.narrow(o, DataSource.class);
this.connection = ds.getConnection();
this.statement = connection.createStatement();
}
catch (SQLException e){System.out.println(e);}
catch(NamingException ne){System.out.println(ne);}
}
public void service.......
public void destroy()
{
try
{
statement.close();
connection.close();
ctx.close();
}
catch (SQLException e){System.out.println(e);}
catch(NamingException ne){System.out.println(ne);}
}
I have a problem with giving back connections to a connectionpool. I suspect the problem to be within the code. I have defined an init method and a destroy method but after two weeks or so the common resource exception occurs. Please take a look at the code and tell me what might be wrong.
private Connection connection;
private Statement statement;
private Context ctx;
public void init(ServletConfig config) throws ServletException
{
super.init(config);
try
{
ctx = new InitialContext();
Object o = ctx.lookup("defaultPool"
DataSource ds = (DataSource) PortableRemoteObject.narrow(o, DataSource.class);
this.connection = ds.getConnection();
this.statement = connection.createStatement();
}
catch (SQLException e){System.out.println(e);}
catch(NamingException ne){System.out.println(ne);}
}
public void service.......
public void destroy()
{
try
{
statement.close();
connection.close();
ctx.close();
}
catch (SQLException e){System.out.println(e);}
catch(NamingException ne){System.out.println(ne);}
}