I have this JSP code which performs a very simple SQL query. The query returns a Clob which has to be converted to a String. I am using Oracle for the database, Resin for the server.
The JSP works just fine most of the time but sometimes it throws a SQLException because the connection was already closed. The exception is thrown during the conversion from Clob to String.
Here is the code causing the issue:
<sql:setDataSource dataSource="jdbc/oracle"/>
<sql:transaction>
<sql:query scope="request" var="query" >
SELECT * FROM TABLE WHERE x=?
<sql:param value="${param.y}"/>
</sql:query>
<c:forEach items="${query.rows}" var="value">
<%
try {
Map map = (Map) pageContext.getAttribute("value");
CLOB clob = ((CLOB) map.get("someClob"));
String str= clob.getSubString(1, (int) clob.length()));
} catch (Exception ex) {
//print out exception
}
%>
</c:forEach>
</sql:transaction>
Has anyone seen this before?
EDIT: using <%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>