当前位置: 技术问答>java相关
在SQL中有函数,比如COUNT(*),怎样通过JDBC调用获得函数值????
来源: 互联网 发布时间:2015-11-09
本文导语: HI | Connection conn= DriverManager.getConnection(url,user,password); Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); String sql="select count(*) as myCount from class"; ...
HI
|
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select count(*) as myCount from class";
ResultSet rs=stmt.executeQuery(sql);
int rcount=0;
if(rs.next())
rcount=rs.getInt(1);
或者
rcount=rs.getInt("myCount");
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select count(*) as myCount from class";
ResultSet rs=stmt.executeQuery(sql);
int rcount=0;
if(rs.next())
rcount=rs.getInt(1);
或者
rcount=rs.getInt("myCount");