如果结果集的值超过30000,我需要从jsp打开div标签。但是如何将rs的值存储为int?
try {
Class.forName("com.ibm.db2.jcc.DB2Driver");
con = DriverManager.getConnection (urlPrefix, "uname", "pwd");
System.out.println("got connection");
stmt = con.createStatement();
String strQuery = "SELECT count(*) FROM tablename where condition stmt";
rs = stmt.executeQuery(strQuery);
if (rs>30000) {
request.getParameter("view");
}
System.out.println("executed query");
} catch(Exception e) {
System.out.println(e);
}
答案 0 :(得分:2)
rs = stmt.executeQuery(strQuery);
stmt.executeQuery返回一个ResultSet对象,我们可以从对象中检索结果
对于你的案例,如下所示的查询。
rs = stmt.executeQuery(strQuery);
int count=0;
if(rs.next()){
count=rs.getInt(1);
}