JDBC closed connection - second time around
This is my mystery...
Within a test JSP, I have code to create a JDBC Connection object, get a connection to a DB2 database, create a Statement object, set up an SQL statement, then get the ResultSet to process. After the ResultSet is processed, the objects are closed.
This is just a test, so I know the next step is to move the data access into a bean. I just need to take this one step at a time.
The funny thing is that the data access works - one time only. Only the first time it is invoked does it return the data from the database. Every time after that, the Connection object will come back with 'isClosed' set to true.
Any clues on why? Does it relate to the closing the objects after the data access is complete?
Thanks - Jim
Are you trying to use the connection created in one jsp in another jsp? Because as far as I know, that is not possible, unless you store the connection in the session. Are you doing that?
Why don't you try to reuse the connection in the same jsp page, like for example make two different queries.. that should work.
Ylan
Ylan -
No, not trying to pass a connection to another jsp - just the code within a single jsp to access a database table and display some data. The access works once, and every time the jsp is refreshed, the connection status flag 'isClosed' is set to true.
I thought that each time the page is invoked, the Connection object would be created anew. Should the Connection, Statement and ResultSet objects be set to null after they are closed?
Jim
I'm having the same exact problem, any help in figuring this out would be appreciated. After I press the submit button the second time the database connection gets dropped alltogather.
here is my code:
<%@ include file = "CheckCredentials.jsp" %>
<jsp:useBean id = "VendLOV" class = "QAVendorLOV" scope = "request"/>
<html>
<head>
<title>Top Frame For Vendor Search</title>
</head>
<body>
<form id="SendSearchName" method="post">
<input type="text" name="VendorSearchName" size="40" maxlength="800">
<input type="submit" value="Search">
</form>
 
 
 
<%
String getVendorName = new String();
getVendorName = request.getParameter("VendorSearchName");
String OutPutText = new String();
try
{
getVendorName.length();
Connection Conn = null;
Conn = CheckCred.ConnectionFinder(session.getId());
OutPutText = VendLOV.GetLOV(Conn, getVendorName);
out.println(OutPutText);
}
catch(SQLException e)
{
out.println(e.getMessage());
}
catch(Exception e)
{
out.println("Caught null exception");
}
%>
 
 
 
<%=CheckCred.CheckSession()%>
</body>
</html>