当前位置: 代码迷 >> Java Web开发 >> 看过《JSP数据库通用模块开发与系统移植》第6章网上聊天室的进来解决方案
  详细解决方案

看过《JSP数据库通用模块开发与系统移植》第6章网上聊天室的进来解决方案

热度:31   发布时间:2016-04-17 11:09:41.0
看过《JSP数据库通用模块开发与系统移植》第6章网上聊天室的进来
这本书挺好的,但是运行代码的时候有一些问题,其中数据库操作被封装在com.chat.Execute_DB中,
比如user_list.jsp页面:
<%@ page contentType="text/html; charset=gb2312" language="java" %>
<%@ page import="java.sql.*,java.util.*"%>
<jsp:useBean scope="page" id="Ex" class="com.chat.Execute_DB" />
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>在线聊友列表</title>
</head>
<body>
<div align="center">
<%
java.util.Date NowDate = new java.util.Date();
//查询当前用户列表
String strSql = "select * from userlist";
ResultSet rs = Ex.exeSqlQuery(strSql);
%>
<p><font size="5"><strong>在线聊友列表</strong></font></p>
<table width="60%" border="0">
<tr bgcolor="#CCCCCC" >
<th width="15%" align="center" height="25">&nbsp;</th>
<th width="25%" align="center" height="25">
用户名
</th>
<th width="30%" align="center" height="25">
所在聊天室
</th>
<th width="30%" align="center" height="25">
登录时间
</th>
</tr>
<%
int i=0;
while(rs.next())
{
String str_ChatRoom = rs.getString("ChatRoom");
String str_UserName = rs.getString("UserName");
strSql = "select LoginTime from users where UserName like '"+str_UserName+"'";
ResultSet rs1 = Ex.exeSqlQuery(strSql);
rs1.next();
long l_LoginTime = rs1.getLong("LoginTime");
rs1.close();
NowDate.setTime(l_LoginTime);
String str_LoginTime = NowDate.toLocaleString();
i++;
%>
<tr bgcolor="#EFEFEF">
<td height="25" align="center"><%=i%></td>
<td height="25" align="left"><%=str_UserName%></td>
<td height="25" align="left">
<%
if(str_ChatRoom.compareTo("xiuxian")==0)
{
out.println("休闲娱乐");
}
else if(str_ChatRoom.compareTo("yuanfen")==0)
{
out.println("缘分天空");
}
else if(str_ChatRoom.compareTo("tantian")==0)
{
out.println("谈天说地");
}
%>
</td>
<td height="25" align="left"><%=str_LoginTime%></td>
</tr>
<%
}
rs.close();
%>
</table>
<br>
<input type="button" name="btn" value="关闭窗口" onClick="javascript:window.close()">
</div>
</body>
</html>

觉得应该没什么问题,但是就是运行不了明明数据库里有东西,就是报错:


org.apache.jasper.JasperException: javax.servlet.ServletException: java.sql.SQLException: Illegal operation on empty result set.
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:541)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:417)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

root cause

javax.servlet.ServletException: java.sql.SQLException: Illegal operation on empty result set.
  相关解决方案