有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java JDBC:如何从结果集中检索SQL COUNT函数的结果?

通常,当我们想要从数据库中检索表中的值时,我们会调用相应的ResultSet方法,并将要检索的列名传递给它

   ResultSet rs= stmt.executeQuery("select name from db.persons where school ='"+sch+"'");
    int count= rs.getString("person_name");

但是,当我们想要获得特定列中的行(或字段)计数时(我们使用SQL count函数),我们如何检索结果呢在下面的代码段中,我应该在rs.getInt()方法中传递什么参数

ResultSet rs= stmt.executeQuery("select count(name) from db.persons where school ='"+sch+"'");
int count= rs.getInt( ????? );

共 (0) 个答案