Using Resultset in Java Program

后端 未结 4 2081
夕颜
夕颜 2021-01-05 01:18
Resultset rs=stmt.executeQuery(\"select count(*) from feedsca group by score order by score\");

Using the above java code above, am retrieving the

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-05 01:40

    As far as my knowledge, your query will only get one row and column i.e., the total number of rows that your query returns.

    Say for example :

    Select count(*) from emp; Generally this query will return a value 14.

    so your java code

    if(rs.next())
        rs.getInt(1); 
    

    will return only one value i.e., 14

    So, How can you access rs.getString(2). This will automatically throws an exception which you got in the second case.

提交回复
热议问题