这本书挺好的,但是运行代码的时候有一些问题,其中数据库操作被封装在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 causejavax.servlet.ServletException: java.sql.SQLException: Illegal operation on empty result set.
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:850)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
org.apache.jsp.user_005flist_jsp._jspService(user_005flist_jsp.java:159)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
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 causejava.sql.SQLException: Illegal operation on empty result set.
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
com.mysql.jdbc.ResultSetImpl.checkRowPos(ResultSetImpl.java:815)
com.mysql.jdbc.ResultSetImpl.getLong(ResultSetImpl.java:2835)
com.mysql.jdbc.ResultSetImpl.getLong(ResultSetImpl.java:2830)
com.mysql.jdbc.ResultSetImpl.getLong(ResultSetImpl.java:2942)
org.apache.jsp.user_005flist_jsp._jspService(user_005flist_jsp.java:106)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
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)请问有哪位和我遇到一样的问题吗?谢谢

解决方案 »

  1.   

    楼主你还是别被这种纯讲jsp+servlet的蒙了,这种纯讲jsp的在jsp里面操作数据库的已经过时了。jsp语法弄明白,基本概念搞清楚就完了。可以开始学习struts框架之类的东西了。
    这种jsp里面嵌套了N多代码的做法,可以很明白的告诉你:自从2002年还是2003年struts1.0出来以后,就很少有人用了。
    为什么?代码可读性极其差!!!!
      

  2.   


    upstairs,how old r u?haha
      

  3.   

    if(rs1.next())
    {
    long l_LoginTime = rs1.getLong("LoginTime");
    rs1.close();
    NowDate.setTime(l_LoginTime);
    }