ResultSet exception - before start of result set

后端 未结 6 937
独厮守ぢ
独厮守ぢ 2020-11-21 23:30

I\'m having trouble getting data from a ResultSet object. Here is my code:

    String sql = \"SELECT type FROM node WHERE nid = ?\";
    PreparedStatement pr         


        
6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-22 00:21

    Basically you are positioning the cursor before the first row and then requesting data. You need to move the cursor to the first row.

     result.next();
     String foundType = result.getString(1);
    

    It is common to do this in an if statement or loop.

    if(result.next()){
       foundType = result.getString(1);
    }
    

提交回复
热议问题