while(rs.next())
{
//这里是查回来的每一条记录
}
{
//这里是查回来的每一条记录
}
解决方案 »
- jsp如何写"下一页 1 2 3 4 5"这部分的代码
- 怎么获取请求地址啊
- 超强版status,不看看 你就不知道天有多高!
- 急救Stucts异常
- 关于用户自己设计表单的问题?
- 求助:一个JSP的ASCII码转化成字符的问题?
- 如何象c/s结构得软件那样从弹出窗口获得参数??(分不够另加!!)
- struts竟然这样,怎么办?
- 本人安装了个jive,想学习一下,单不只从何处下手,请大家介绍一下
- 请问这是为什么(jsp中的表单提之后为什么中文全都变成了???????)
- 如何在网页上隐藏真正的连接,防止别人提交后刷新又从新提交一次?
- 找不到isapi_redirector2.dll文件,能否给个下载连接。 万分感谢!
int i;
while(rs.next())
{
i++;
}
如果i=0那就没有符合查询条件的记录
rs返回一个ResultSet类型的值
//无匹配记录
}else{
//有匹配的记录
}
select count(*) from table//可以用来查询数据记录的条数!
这个是调用的procedure,而且你的procedure里返回的是null,否则就用:
while(rs.next())
{
//这里是查回来的每一条记录
}
我的意思是这样的,我查询符合条件的记录,如果有就用表格的形式将它在这个页面都显示出来,如果没有一个符合条件的话就在这个页面只显示一句话做为提示。
(rs==null)或者是(!rs)我都试了,还是不行,请问有其他的办法吗?
兄弟刚学的,请各位大侠不吝赐教!谢谢!
看了这么多的回复,却没有满意的。。我写了两句,看看行否if(null!=rs){
while(rs.next){
//这里可以做你的取数据集的值。。
}}
如果需要取值的话,请用rs.getString();
<%@ page language="java" import = "java.sql.*,java.util.*" contentType="text/html;charset=gb2312"%>
<html>
<head>
<title>个人请假查询</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body background="image/bj.gif">
<% try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:DNS1");
Statement smt=con.createStatement();
String getpersonID=(String)session.getAttribute("personID");
String sql = "SELECT * FROM db WHERE (条件)";
ResultSet rs=smt.executeQuery(sql);if(?????){
con.close();
%>
<p align="center">您到目前为止还没有请假记录!</p>
<p align="center"><a href="userBack.jsp">返回</a></p>
</body>
<% }
else{
%>
<form id="S_form" name="S_form" method="post" action="" >
<table border=1 align="center" bordercolor="#008000">
<tr bgcolor="#99FFFF">
<td width="10%" height="16">
<p align="center">人员姓名</p></td>
</tr>
<%
}
con.close();
%>
</table>
</form>
<p align="center"><a href="userBack.jsp">返回</a></p>
</body>
<% }
}
catch(Exception e){out.println(e.getMessage());}
%>
</html>
if()中要填什么语句呀,用(rs==null)或(!rs.next())都不行,出现的问题是有这么几种:
1)当没有记录的时候,不能显示我的那句提示话,而显示一个表头
2)当有两条记录时就显示一条,当有一条时就只显示一个表头。
这要怎么办?
我的要求是:当没有任何记录时,就显示那句提示的话,和返回的连接,其余的都不显示(不能显示表头),
当有记录是就显示表头和实际的记录条数都能显示出来。
请大家帮一下呀 !感谢!
%><form id="S_form" name="S_form" method="post" action="" >
<table border=1 align="center" bordercolor="#008000">
<tr bgcolor="#99FFFF">
<td width="10%" height="16">
<p align="center">人员姓名</p></td>
</tr>
<%
do{
%>
<tr bgcolor="#99FFFF">
<td width="10%" height="16">
<p align="center"><%=rs.getString("你的人员姓名的字段名字")%></p></td>
</tr>}while(rs.next());con.close();
%>
</table>
</form>
<p align="center"><a href="userBack.jsp">返回</a></p>
</body>} else{ %>//endif
<p align="center">您到目前为止还没有请假记录!</p>
<p align="center"><a href="userBack.jsp">返回</a></p>
<%}%>//endelse
可是有一点,我不太明白就是我前面也是按照的你的这种方法,有一个地方不同,你用的是do{}while(),
而我用的是while(){},如下:
if(rs.next()){
%><form id="S_form" name="S_form" method="post" action="" >
<table border=1 align="center" bordercolor="#008000">
<tr bgcolor="#99FFFF">
<td width="10%" height="16">
<p align="center">人员姓名</p></td>
</tr>
<%
while(rs.next()){
%>
<tr bgcolor="#99FFFF">
<td width="10%" height="16">
<p align="center"><%=rs.getString("你的人员姓名的字段名字")%></p></td>
</tr>}con.close();
%>
</table>
</form>
<p align="center"><a href="userBack.jsp">返回</a></p>
</body>} else{ %>//endif(省略)
它出现这样的问题:如果没有记录能正确显示提示语句,但当只有一条记录时却只显示一个表头,有两条时才显示一条,三条就显示两条,这是为什么?????
谢谢!
而while(条件){}先判断再做的话,当有多条记录时也是会丢掉最后一条记录,怎么会丢掉第一条记录呢?
每天都会有大量的供求信息发布!要做兼职的可以上来看看
noco赌场!可以在这里赚取大量的cp点数
noco考场!可以在这里证明你的开发能力
noco道具市场!购买你需要的道具!让noco更有意思
noco精灵市场!购买精灵为你作战!
noco = note + code + er
next
public boolean next()
throws SQLExceptionMoves the cursor down one row from its current position. A ResultSet cursor is initially positioned before the first row; the first call to the method next makes the first row the current row; the second call makes the second row the current row, and so on.
If an input stream is open for the current row, a call to the method next will implicitly close it. A ResultSet object's warning chain is cleared when a new row is read.
Returns:
true if the new current row is valid; false if there are no more rows
Throws:
SQLException - if a database access error occurs那么你的错误在于:
在if(判断)之后就已经指向第一个记录了(如果有的话),如果成功进入while,那么第一次循环的时候由于在while(判断)又一次调用next()函数,那么第一次打印的时候自然就会吧第一条记录给漏掉了。不知道这样表述你明白没有。
int i=0;
while(rs.next())
{
i++;
}
if(i==0){
//想做什么就做什么吧!
}else{
//想做什么就做什么吧!
}