jsp与数据库的怪问题!?是怎么回事啊!? ResultSet Rs=stmt.executeQuery(sql);Rs.next();//在这加一句out.print(Rs.getInt("id")); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这样是行了。可为什么我的留言本不行呢!?这是怎么回事?!这个的源程序上有Rs.next();啊。我还要怎么写啊?!<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" %><html><head><title>留言本</title><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><link href="css/style" rel="stylesheet" type="text/css"></head><jsp:useBean id="guestbook" class="guestbook.GuestBookJdbc" scope="page"/><body bgcolor="#EBEBEB"><table width="776" border="0" align="center" cellpadding="1" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#FFFFFF"> <tr> <td height="28" align="center" bgcolor="#EBEBEB">留言本</td> </tr> <tr> <td height="24" align="center" bgcolor="#EBEBEB"><a href="add.jsp">添加留言</a> 返回主页 站长邮件 留言系统 </td> </tr></table><% Connection Conn=guestbook.GetConn(); Statement stmt=Conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY); String sql="select * from Guestbook order by id DESC"; ResultSet Rs=stmt.executeQuery(sql); int intPageSize; //一页显示的记录数 int intRowCount; //记录总数 int intPageCount; //总页数 int intPage; //待显示页码 String strPage; int i; //设置一页显示的记录数 intPageSize = 6; //取得待显示页码 strPage = request.getParameter("page"); if(strPage==null){//表明在QueryString中没有page这一个参数,此时显示第一页数据 intPage = 1; } else{//将字符串转换成整型 intPage = java.lang.Integer.parseInt(strPage); if(intPage< 1) intPage = 1; } //获取记录总数 Rs.last(); intRowCount = Rs.getRow(); //记算总页数 intPageCount = (intRowCount+intPageSize-1) / intPageSize; //调整待显示的页码 if(intPage >intPageCount) intPage = intPageCount; if(intPageCount >0){ //将记录指针定位到待显示页的第一条记录上 Rs.absolute((intPage-1) * intPageSize+1); //显示数据 i = 0; while(i< intPageSize && !Rs.isAfterLast()){ %><table width="776" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF"> <tr bgcolor="#EBEBEB"> <td width="143" height="25" align="center">姓名:<%=Rs.getString("username")%></td> <td width="100" align="center"><a href="<%=Rs.getString("url")%>">主页</a> </td> <td width="100" align="center"><a href="mailto:<%//Rs.getString("email")%>">邮件</a> </td> <td width="100" align="center">QQ :<%=Rs.getString("qq")%></td> <td width="100" align="center"><a href="reinfo.jsp?id=<%out.print(Rs.getInt("id"));%>">回复</a></td> <td width="100" align="center"><a href="del.jsp?id=<%//id%>">删除</a></td>///这个地方如何取得id?!!? </tr> <tr bgcolor="#EBEBEB"> <td height="42" rowspan="3" align="center"> </td> <td height="17" colspan="5">留言内容:</td> </tr> <tr> <td height="31" colspan="5" bgcolor="#EBEBEB"> <%String content=Rs.getString("content"); if(content!="") { out.print(content); }%> </td> </tr> <tr> <td height="22" colspan="5" bgcolor="#EBEBEB">回复内容: <%String recontent=Rs.getString("recontent"); if(recontent!=null) { out.print(recontent); }%> </td> </tr></table><% Rs.next(); i++; } %> <table width="776" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td height="22" align="center" bgcolor="#EBEBEB">第<%=intPage%>页 共<%=intRowCount%>条记录/共<%=intPageCount%>页 <% } else{ out.print("目前还没有内容!"); }%> </td> </tr></table></body></html> 出现什么问题了其实你直接while(rs.next())就行了,如果数据到头了会返回false的 同意楼上的,直接用while作循环就可以了! ///这个地方如何取得id?!!?同一条ResultSet的getXXXX()方法好像对同一个字段不能重复使用,所以最好用int id=Rs.getInt("id");然后再访问id这个变量为好. 加上rs.next(),要修改数据集的指针,才能取到你想要的记录 textarea 换行问题 大家好!我想学习JSP,但不知道用什么编程工具好,请大家帮忙推荐!!谢谢! 关于提取某字符串的问题!!!!!!!!!!!!!! 请问怎样才能出现下载文件对话框??? 大家都来侃(雅俗共赏不给分) EL表达式的问题 jsp+ORACLE9i遇到的问题~~~ 学JSP一定要会JAVASCRIPT吗 servlet使用RequestDispatcher到jsp页面,浏览器url栏还是servlet 想建个人网站,有java基础,问点空间租用和博客平台的问题 大家一起来交流...顺便散分...^_^ 建立数据库并写入数据成功!但读不出数据,高手指点!
啊。我还要怎么写啊?!<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" %>
<html>
<head>
<title>留言本</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="css/style" rel="stylesheet" type="text/css">
</head>
<jsp:useBean id="guestbook" class="guestbook.GuestBookJdbc" scope="page"/>
<body bgcolor="#EBEBEB"><table width="776" border="0" align="center" cellpadding="1" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#FFFFFF">
<tr>
<td height="28" align="center" bgcolor="#EBEBEB">留言本</td>
</tr>
<tr>
<td height="24" align="center" bgcolor="#EBEBEB"><a href="add.jsp">添加留言</a>
返回主页 站长邮件 留言系统 </td>
</tr>
</table>
<%
Connection Conn=guestbook.GetConn();
Statement stmt=Conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
String sql="select * from Guestbook order by id DESC";
ResultSet Rs=stmt.executeQuery(sql);
int intPageSize; //一页显示的记录数
int intRowCount; //记录总数
int intPageCount; //总页数
int intPage; //待显示页码
String strPage;
int i;
//设置一页显示的记录数
intPageSize = 6; //取得待显示页码
strPage = request.getParameter("page");
if(strPage==null){//表明在QueryString中没有page这一个参数,此时显示第一页数据
intPage = 1;
} else{//将字符串转换成整型
intPage = java.lang.Integer.parseInt(strPage);
if(intPage< 1) intPage = 1;
}
//获取记录总数
Rs.last();
intRowCount = Rs.getRow();
//记算总页数
intPageCount = (intRowCount+intPageSize-1) / intPageSize;
//调整待显示的页码
if(intPage >intPageCount) intPage = intPageCount;
if(intPageCount >0){
//将记录指针定位到待显示页的第一条记录上
Rs.absolute((intPage-1) * intPageSize+1);
//显示数据
i = 0;
while(i< intPageSize && !Rs.isAfterLast()){
%>
<table width="776" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF">
<tr bgcolor="#EBEBEB">
<td width="143" height="25" align="center">姓名:<%=Rs.getString("username")%></td>
<td width="100" align="center"><a href="<%=Rs.getString("url")%>">主页</a> </td>
<td width="100" align="center"><a href="mailto:<%//Rs.getString("email")%>">邮件</a> </td>
<td width="100" align="center">QQ :<%=Rs.getString("qq")%></td>
<td width="100" align="center">
<a href="reinfo.jsp?id=<%out.print(Rs.getInt("id"));%>">回复</a></td>
<td width="100" align="center"><a href="del.jsp?id=<%//id%>">删除</a></td>
///这个地方如何取得id?!!?
</tr>
<tr bgcolor="#EBEBEB">
<td height="42" rowspan="3" align="center"> </td>
<td height="17" colspan="5">留言内容:</td>
</tr>
<tr>
<td height="31" colspan="5" bgcolor="#EBEBEB">
<%String content=Rs.getString("content");
if(content!="")
{
out.print(content);
}%>
</td>
</tr>
<tr>
<td height="22" colspan="5" bgcolor="#EBEBEB">回复内容:
<%String recontent=Rs.getString("recontent");
if(recontent!=null)
{
out.print(recontent);
}%>
</td>
</tr>
</table>
<%
Rs.next();
i++;
}
%>
<table width="776" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td height="22" align="center" bgcolor="#EBEBEB">第<%=intPage%>页 共<%=intRowCount%>条记录/共<%=intPageCount%>页
<% }
else{
out.print("目前还没有内容!");
}%>
</td>
</tr>
</table>
</body>
</html>
其实你直接while(rs.next())就行了,如果数据到头了会返回false的
要修改数据集的指针,才能取到你想要的记录