2012-04-21 106 views
0

使用会话时得到sql.exception的错误,我有使用会话的一些问题。在view.jsp中,我获取用户名和密码并将它们传递给portlet类。然后,我从获取数据库用户的信息,并保存在会话,并使用“actionResponse.setRenderParameter(” jspPage“‘/ patientInfo.jsp’)”命令去patientInfo.jsp。我得到的用户信息,并用下面的代码打印出来:在Liferay的门户

<% 
ResultSet comments = (ResultSet)portletSession.getAttribute("comments"); 
ResultSet patientInfo = (ResultSet)portletSession.getAttribute("patientInfo"); 
patientInfo.next();   
%> 
<table> 
<tr> 
    <th><strong>Patient Name</strong></th> 
    <th><strong>Insuline dose</strong></th> 
</tr> 
<tr> 
    <td class="info"><%=patientInfo.getString("FirstName") + patientInfo.getString("LastName")%></td> 
    <td class="info"><%=Integer.toString(patientInfo.getInt("InsulinDose"))%></td> 
</tr> 

在这个页面中有是去patientProfile.jsp链接:

<portlet:renderURL var="patientProfileURL"> 
    <portlet:param name="jspPage" value="/patientProfile.jsp" /> 
</portlet:renderURL> 

<a href="<%= patientProfileURL%>">Edit Profile</a></p> 

一切正常至今。但是,当我打patientProfile.jsp的后退链接使用下面的代码要回去patientInfo.jsp我得到“java.SQL.Excqption:结果集结束之后”错误的堆栈跟踪和“门户是teprorily不可用”浏览器错误:

<portlet:renderURL var="patientInfoURL"> 

    <portlet:param name="jspPage" value="/patientInfo.jsp" /> 

</portlet:renderURL> 

<p><a href="<%= patientInfoURL %>">Back</a></p> 

回答

0

ResultSets和一些JDBC驱动程序支持的一切都是保存在会话中的坏事。通常,他们需要在后端数据库连接 - ,连接将被重用的第一笔交易(和页面渲染)后的下一交易完成,所以你看到的例外。

你应该拷贝你有的对象(你怎么从数据库中检索它们呢?plain/pure jdbc access?)到一些没有任何数据库连接的业务/数据传输对象。

+0

这是我如何连接到数据库并从数据库检索数据: java.lang.Class.forName(_jdbcDriver); 连接= java.sql.DriverManager.getConnection(dbURL,数据库用户名,DBPASSWORD); Statement statement = connection.createStatement(); resultSet = statement.executeQuery(sql); – Karadous 2012-04-21 16:58:12

+0

不要这样做。不要长时间保留从JDBC API返回的结果 - 它会限制应用程序的可伸缩性,并且保留可能被释放的资源锁定。可能还会冒着超时或 - 如你所见 - 其他问题。 – 2012-04-22 09:48:17