Ben Souther wrote:Can you post a short example of how you're getting an using the connection from within your Java code?
The following connection method for getting the connection. I am establishing a connection in my action class and i am having dao. After finishing the data base operation then i am closing the statment etc., at last i am closing the connection in my action class. This s a process for getting and closing connection.
public Connection getConnection() {
Connection con = null;
try {
initContext = new InitialContext();
if (initContext != null) {
Context envContext = (Context) initContext
.lookup("java:/comp/env");
DataSource ds = (DataSource) envContext.lookup("jdbc/agent");
con = ds.getConnection();
if (ds != null) {
con = ds.getConnection();
in++;
}
log.info("Request Con No :: " + in);
log.info("Con :: " + con);
}
} catch (NamingException e) {
e.printStackTrace(pw);
log.error(sw);
} catch (SQLException e) {
e.printStackTrace(pw);
log.error(sw);
}
return con;
}
------------------------------------
Close
====
public void closeInitContext(Connection con) {
try {
if (con != null)
con.close();
if (initContext != null)
initContext.close();
in--;
} catch (NamingException e) {
e.printStackTrace(pw);
log.error(sw);
} catch (SQLException e) {
e.printStackTrace(pw);
log.error(sw);
} finally {
log.info("After Close Con No :: " + in);
}
}