How do you access the value of an SQL count () query in a Java program

前端 未结 7 1299
梦毁少年i
梦毁少年i 2021-02-01 00:54

I want to get to the value I am finding using the COUNT command of SQL. Normally I enter the column name I want to access into the getInt() getString() method, what do I do in t

7条回答
  •  天命终不由人
    2021-02-01 00:58

    I have done it this way (example):

    String query="SELECT count(t1.id) from t1, t2 where t1.id=t2.id and t2.email='"r@r.com"'";
    int count=0;
    try {
        ResultSet rs = DatabaseService.statementDataBase().executeQuery(query);
        while(rs.next())
            count=rs.getInt(1);
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        //...
    }
    

提交回复
热议问题