关于jsp数据库查询问题

cjnsrj 2006-04-14 05:04:57
我在一个jsp查询页面中放置了三个查询条件:楼号,层号,房间号。现在我用楼号,层号,房间号查询以及用楼号,层号查询来达到显示不同的查询结果。在查询结果页面中,我用
if("房间号为空")
{
显示用楼号,层号为查询条件的查询结果;
}
else{
显示用楼号,层号,房间号为查询条件的查询结果;
}

在调试时,当未输入房间号时,点击查询按钮时,if中的语句并不执行。执行的仍是else中的内容。
这种情况如何处理。谢谢!
...全文
87 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
feixue6511 2006-04-14
  • 打赏
  • 举报
回复
if(fangHao == null || fangHao.equals("")||fangHao.equals("0")){

}
cjnsrj 2006-04-14
  • 打赏
  • 举报
回复
我写的如下:
<%
String distN=request.getParameter("distNum");
String roomN=request.getParameter("roomNum");
String floorN=request.getParameter("floorNum");
%>
if(roomN==null) {
<%
try {
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url = "jdbc:mysql://localhost/xuesheng?user=root&password=wanzhang&Unicode=true&characterEncoding=gb2312";
Connection con = DriverManager.getConnection(url);
Statement stmt=con.createStatement();
ResultSet rs;
String SqlQue="SELECT deviceuse.roomNum,devNum,useCt FROM relation,district,deviceuse where deviceuse.roomNum='"
+roomN+"' and district.distNum='"
+distN+"' and relation.floorNum='"
+floorN+"'";
//out.print(SqlQue);
rs = stmt.executeQuery(SqlQue);
while(rs.next()){
%>
<tr class="normal">
<td width="88"><%=rs.getString("roomNum")%></td>
<td width="171"><%=rs.getString("devNum")%></td>
<td width="166"><%=rs.getString("useCt")%></td>
</tr>

<% }

stmt.close();
con.close();
}
catch(SQLException ex){out.print(ex.toString());}

%>
<% } else {
<%
try {
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url = "jdbc:mysql://localhost/xuesheng?user=root&password=wanzhang&Unicode=true&characterEncoding=gb2312";
Connection con = DriverManager.getConnection(url);
Statement stmt=con.createStatement();
ResultSet rs;
String SqlQue="SELECT deviceuse.roomNum,devNum,useCt FROM relation,district,deviceuse where deviceuse.roomNum='"
+roomN+"' and district.distNum='"
+distN+"' and relation.floorNum='"
+floorN+"'";
//out.print(SqlQue);
rs = stmt.executeQuery(SqlQue);
while(rs.next()){
%>
<tr class="normal">
<td width="88"><%=rs.getString("roomNum")%></td>
<td width="171"><%=rs.getString("devNum")%></td>
<td width="166"><%=rs.getString("useCt")%></td>
</tr>

<% }

stmt.close();
con.close();
}
catch(SQLException ex){out.print(ex.toString());}

%>
}%>
wsk_228 2006-04-14
  • 打赏
  • 举报
回复
楼上已解...
pdvv 2006-04-14
  • 打赏
  • 举报
回复
if(fangHao == null || fangHao.equals("")){

}
伟大的左前卫 2006-04-14
  • 打赏
  • 举报
回复
if不执行,说明条件不满足,"房间号为空"具体你是怎么写的?

81,115

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧