关于while循环的问题,给50分
请高手帮忙看一段代码,应该显示出三条记录的,但是只显示一条记录,循环只执行了一次,如果把if之中的语句去掉,就能正常显示三条记录,还发现如果if里边有数据库查询语句的话,也只能执行一次循环,sql语句应该没有错误,想请各位高手看看到底如何修改循环才能正常执行,多谢了!
String begin_time="";
String glnum="";
String jh="";
rs = stmt.executeQuery("SELECT GLNUM,jh,BEGIN_TIME from zqrb where rq=to_date( '"+date1+"','YYYY-MM-DD')");
while (rs.next())
{
j=j+1;
begin_time=rs.getString("begin_time");
glnum=rs.getString("glnum");
jh=rs.getString("jh");
if(begin_time==null)
{
rs1 = stmt.executeQuery("select max(rq) as maxrq from zqrb where rq<to_date('"+date1+"','YYYY-MM-DD') and begin_time is not null and glnum='"+glnum+"' and jh='"+jh+"'");
while (rs1.next())
{
maxrq=rs1.getString("maxrq");
}
rs1.close();
date1=maxrq.substring(0,10);
rs2 = stmt.executeQuery("select begin_time from zqrb where rq=to_date('"+date1+"','YYYY-MM-DD') and glnum='"+glnum+"' and jh='"+jh+"'");
while (rs2.next())
{
begin_time=rs2.getString("begin_time");
}
rs2.close();
}
%>
<%=glnum%>,<%=jh%>,<%=date1%>,<%=begin_time%><br>
<%
}
rs.close();
%>
String begin_time="";
String glnum="";
String jh="";
rs = stmt.executeQuery("SELECT GLNUM,jh,BEGIN_TIME from zqrb where rq=to_date( '"+date1+"','YYYY-MM-DD')");
while (rs.next())
{
j=j+1;
begin_time=rs.getString("begin_time");
glnum=rs.getString("glnum");
jh=rs.getString("jh");
if(begin_time==null)
{
rs1 = stmt.executeQuery("select max(rq) as maxrq from zqrb where rq<to_date('"+date1+"','YYYY-MM-DD') and begin_time is not null and glnum='"+glnum+"' and jh='"+jh+"'");
while (rs1.next())
{
maxrq=rs1.getString("maxrq");
}
rs1.close();
date1=maxrq.substring(0,10);
rs2 = stmt.executeQuery("select begin_time from zqrb where rq=to_date('"+date1+"','YYYY-MM-DD') and glnum='"+glnum+"' and jh='"+jh+"'");
while (rs2.next())
{
begin_time=rs2.getString("begin_time");
}
rs2.close();
}
%>
<%=glnum%>,<%=jh%>,<%=date1%>,<%=begin_time%><br>
<%
}
rs.close();
%>
...全文
相关推荐
java基础编程题50道有答案
java基础编程题50道,包括答案/java基础编程题50道,包括答案/java基础编程题50道,包括答案
do-while循环——while循环
有详细的讲解和对应的案例注释,对开发人员有很打的帮助!
while循环练习示例
本资源内部包含了while循环的练习代码,以及我之前发的所有的练习代码
python中使用while循环的实例
在本篇内容里小编给各位整理的是关于python中使用while循环的实例以及相关知识点,需要的朋友们学习下。
MySQL循环语句之while循环测试
mysql 操作同样有循环语句操作,网上说有3中标准的循环方式: while 循环 、 loop 循环和repeat循环。还有一种非标准的循环: goto。 鉴于goto 语句的跳跃性会造成使用的的思维混乱,所以不建议使用。 这几个循环语句的格式如下: WHILE……DO……END WHILE REPEAT……UNTIL END REPEAT LOOP……END LOOP GOTO。 目前我只测试了 while 循环: delimiter $$ // 定义结束符为 $$ drop procedure if exists wk; // 删除 已有的 存储过程 create procedu


Web 开发
