使用JDBC获取select count(*) from table_name
public int getCount() {
int count = 0;
PreparedStatement ps = null;
ResultSet rs = null;
String sql = "select count(*) from table_name";
try {
con=this.getConnection();
if (con!=null) {
ps=con.prepareStatement(sql);
rs=ps.executeQuery();
if(rs.next()) {
count=rs.getInt(1);
System.out.println("count:"+count);
}
}
} catch (Exception e) {
// TODO: handle exception
}
return count;
} 阅读更多
int count = 0;
PreparedStatement ps = null;
ResultSet rs = null;
String sql = "select count(*) from table_name";
try {
con=this.getConnection();
if (con!=null) {
ps=con.prepareStatement(sql);
rs=ps.executeQuery();
if(rs.next()) {
count=rs.getInt(1);
System.out.println("count:"+count);
}
}
} catch (Exception e) {
// TODO: handle exception
}
return count;
} 阅读更多
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
- 上一篇:没有了
- 下一篇:没有了