V
vivienne wykes
Hi All,
Could anyone explain simply the implications of not closing a
resultset,statement, and connection as shown below or provide a link to an
explanation ?
I had a problem on a shared server (resin) and I think my webapp was causing
an issue for other server users by not closing the db connection.
Is it a case of that there is certain amount of connections available to a
server and not closing the connection ?
Any guidance appreciated.
Regards
Code below
<%
//-------------------make connection-------------------------------------
Class.forName("org.gjt.mm.mysql.Driver");
java.sql.Connection connection =
java.sql.DriverManager.getConnection("jdbc:mysql://localhost/shop");
java.sql.Statement statement = connection.createStatement();%>
</td>
</tr>
<tr valign="top" class="footer">
<td height="25" colspan="2" class="bodytext"> <%
if(session.getAttribute("welcome") != null) { %> <h3> <%=
session.getAttribute("welcome") %> </h3>
<%String weddingid=request.getParameter("weddingid");
if (!weddingid.equals("paulonly")){%>
Click <a href="<%=
response.encodeURL("shop-products.jsp?weddingid="+weddingid) %>">here</a>
to view your wedding pictures
<%}
else {%>
Click <a href="<%=
response.encodeURL("pauls_jedi_interface.jsp") %>">here</a>
to enter JEDI
<%}
} else { %>
Please log in below to continue...
<form action="<%= response.encodeURL("db-result.jsp") %>"
method="get">
<table class="bodytext">
<tr>
<%java.sql.ResultSet RS3 = statement.executeQuery("SELECT
* FROM items ORDER BY weddingid");%>
<td nowrap>Select Wedding:</td>
<td><select name="weddings_to_view" class="dropdown"
onChange="MM_jumpMenu('parent',this,0)">
<option selected><%=selected%></option>
<%while(RS3.next()){//open while
String weddingid2 = RS3.getString("weddingid");
if (!last_wedding_id.equals(weddingid2)){// open if%>
<option
value="<%=response.encodeURL("db-login.jsp?selected="+weddingid2)%>"><%=wedd
ingid2%></option>
<%} //close if
last_wedding_id = weddingid2;
}//close while
//-------------------close result set close statement close
connection-------------------------------------
RS3.close();
statement.close();
connection.close();%>
Could anyone explain simply the implications of not closing a
resultset,statement, and connection as shown below or provide a link to an
explanation ?
I had a problem on a shared server (resin) and I think my webapp was causing
an issue for other server users by not closing the db connection.
Is it a case of that there is certain amount of connections available to a
server and not closing the connection ?
Any guidance appreciated.
Regards
Code below
<%
//-------------------make connection-------------------------------------
Class.forName("org.gjt.mm.mysql.Driver");
java.sql.Connection connection =
java.sql.DriverManager.getConnection("jdbc:mysql://localhost/shop");
java.sql.Statement statement = connection.createStatement();%>
</td>
</tr>
<tr valign="top" class="footer">
<td height="25" colspan="2" class="bodytext"> <%
if(session.getAttribute("welcome") != null) { %> <h3> <%=
session.getAttribute("welcome") %> </h3>
<%String weddingid=request.getParameter("weddingid");
if (!weddingid.equals("paulonly")){%>
Click <a href="<%=
response.encodeURL("shop-products.jsp?weddingid="+weddingid) %>">here</a>
to view your wedding pictures
<%}
else {%>
Click <a href="<%=
response.encodeURL("pauls_jedi_interface.jsp") %>">here</a>
to enter JEDI
<%}
} else { %>
Please log in below to continue...
<form action="<%= response.encodeURL("db-result.jsp") %>"
method="get">
<table class="bodytext">
<tr>
<%java.sql.ResultSet RS3 = statement.executeQuery("SELECT
* FROM items ORDER BY weddingid");%>
<td nowrap>Select Wedding:</td>
<td><select name="weddings_to_view" class="dropdown"
onChange="MM_jumpMenu('parent',this,0)">
<option selected><%=selected%></option>
<%while(RS3.next()){//open while
String weddingid2 = RS3.getString("weddingid");
if (!last_wedding_id.equals(weddingid2)){// open if%>
<option
value="<%=response.encodeURL("db-login.jsp?selected="+weddingid2)%>"><%=wedd
ingid2%></option>
<%} //close if
last_wedding_id = weddingid2;
}//close while
//-------------------close result set close statement close
connection-------------------------------------
RS3.close();
statement.close();
connection.close();%>