当前位置: 技术问答>java相关
SQL中有count这个函数,请问如何将这个值取出
来源: 互联网 发布时间:2015-02-23
本文导语: 代码如下 stm=con.prepareStatement("select count(memberno) from table"); ResultSet result=stm.executeQuery(); 我需要table中memberno的个数,那么如何从result中提出需要的值呢? | stm=con.prepareStatement("select count(memberno) membernoco...
代码如下
stm=con.prepareStatement("select count(memberno) from table");
ResultSet result=stm.executeQuery();
我需要table中memberno的个数,那么如何从result中提出需要的值呢?
stm=con.prepareStatement("select count(memberno) from table");
ResultSet result=stm.executeQuery();
我需要table中memberno的个数,那么如何从result中提出需要的值呢?
|
stm=con.prepareStatement("select count(memberno) membernocount from table");
ResultSet result=stm.executeQuery();
int count_memberno=0;
if (result.next()){
count_memberno=result.getInt("membernocount");
}
ResultSet result=stm.executeQuery();
int count_memberno=0;
if (result.next()){
count_memberno=result.getInt("membernocount");
}
|
SQL = "select count(memberno) as memberno from table"
然后从记录集中取字段memberno的值即可
然后从记录集中取字段memberno的值即可