日期:2014-05-18  浏览次数:20854 次

executeQuery的问题
<%
String   s_url= "jdbc:oracle:thin:@localhost:1521:sun1 ";
Connection   con=DriverManager.getConnection(s_url, "chat ", "chat ");

Statement   smt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);

ResultSet   rs;
String   sql,s_username;

sql= "select   username   from   user_state ";

rs=smt.executeQuery(sql);

while(rs.next())
        {
        s_username=rs.getString( "username ");
        out.println(s_username+ " <br   /> ");
        }

rs.close();
smt.close();
%>

这有一个问题,如果user_state一行数据也没有,好象就要报错,我想让这个页面什么都不显示或者显示 "无人员信息 "这几个字

------解决方案--------------------
rs.close();
smt.close();
把这个try catch了,
------解决方案--------------------
<% ResultSet rs=smt.executeQuery(sql);
s_username=rs.getString( "username ");
if (s_username.equals( " ")){ %>
无人员信息!
<%}else{
while(rs.next())
{
out.println(s_username+ " <br /> ");
}

rs.close();
smt.close();


}%>
------解决方案--------------------
if(rs == null){
out.println( "无人员信息 ");
}else{
while(rs.next())
{
s_username=rs.getString( "username ");
out.println(s_username+ " <br /> ");
}
}
------解决方案--------------------
应该不会报错的,如果要显示无人员
if(!rs.next()) {
out.println( "无人员信息 ");
} else {
do {
s_username=rs.getString( "username ");
out.println(s_username+ " <br /> ");
} while(rs.next())
}