0

次のような例外が発生しています

java.sql.SQLException: Before start of result set when calling getInt() method  

私のコードは次のとおりです:::

public void setdateTOSource(){
   try{
        String q = "SELECT * FROM ipp.resource;";
        ResultSet result = DB_Access.getData(q);
        System.out.println("Size result set"+result.getFetchSize());
        while(result.next()){
            getIpSource().add(result.getString(1)); 
            System.out.println(result.getString(1));

        }
       System.out.println("source size "+getIpSource().size());      
   }
   catch(Exception e){
       System.out.println(e);
   }
}
public void insertTargetToDb(List<String> targetValue){

    try{
        Connection con = DB_Connect.getDataBaseConnection();
        Statement statement1 = con.createStatement();

        int val=0;
        String q1 = "SELECT MAX(area_id) as aa FROM ipp.area;";
        ResultSet resultset = statement1.executeQuery(q1); 
        if(resultset.next()){
            val = resultset.getInt(1);
         };           
        val++;

        String q2 = "INSERT INTO ipp.area VALUES("+val+",'"+getAreaName()+"',1);";
        Statement statement2 = con.createStatement();
        statement1.executeUpdate(q2);
        for( int y=0;y<targetValue.size();y++){

           System.out.println("FS");

           String ip=targetValue.get(y);
           System.out.println("ip" +ip);
           String q3 ="SELECT resource_id FROM ipp.resource r where ip_address like '"+ip+"%';";
           Statement statement3 = con.createStatement();
           ResultSet resultset3 =statement3.executeQuery(q3);

           System.out.println("FS1");
//           ResultSet result1 =DB_Access.getData(q3);
           System.out.println("FS2");
           System.out.println("result set"+resultset3.getFetchSize());
 //====================================================================              
while(resultset3.next()){
                setId(resultset.getInt(1));
          }           
          System.out.println("result :........."+resultset3.getInt("resource_id"));
          System.out.println("FS3");

           String q4 = "INSERT INTO ipp.used_resource VALUES("+val+","+getId()+");";
           Statement statement4= con.createStatement();
           statement4.executeUpdate(q4);
//           DB_Access.setData(q3);
           statement3.close();
           statement4.close();
//           resultset3.close();
        }
        resultset.close();
        statement1.close();
        statement2.close();
        con.close();
        addMessage("Area created Successfully");


    }
    catch(Exception e){
        System.out.println(e);
    }
}

例外は行の後に来る

//========================== resource_id は整数値です

4

1 に答える 1

3

この行

while(resultset3.next()){
                setId(resultset.getInt(1));
          } 

と交換する必要がありますか?

while(resultset3.next()){
                setId(resultset3.getInt(1));
          } 
于 2013-02-15T10:16:57.933 に答える