0

I am trying to store the DB value into two different array. if test_type is ”New”=> store first array, else=> second array. Am getting “SEVERE: null java.sql.SQLException: No data found error” while assign rs.getString value to variable\array. Could anyone help me to solve the issue? Am using MS access as DB

code:

try {   
   DatabaseConnectivity();      
   stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_READ_ONLY);
   String select="Select * from (SELECT DISTINCT test_name,test_type FROM ScenarioTable)order by test_type ";                
   ResultSet rs = stmt.executeQuery(select);  
   String colvalues;
   String print="null";
   int arycount=1;
   basicarray=new String [20][20];
   newarray=new String [20][20];                
   while (rs.next()) { 
     print=rs.getString(1);
     if (print.equals("New")) {
          for(int itration=1;itration<=2;itration++) {                               
             colvalues=rs.getString(itration);                                                        
             newarray[arycount][itration]=colvalues;
          } 
     } else {
         for(int itration=1;itration<=2;itration++) { 
            colvalues=rs.getString(itration);                                                        
            basicarray[arycount][itration]=colvalues;
         }
        arycount++;
    }  

error:

Connection Successful
May 04, 2015 8:26:37 AM NewJFrame btn_refreshActionPerformed
SEVERE: null
java.sql.SQLException: No data found
    at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7145)
    at sun.jdbc.odbc.JdbcOdbc.SQLGetDataString(JdbcOdbc.java:3914)
    at sun.jdbc.odbc.JdbcOdbcResultSet.getDataString(JdbcOdbcResultSet.java:5697)
    at sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbcResultSet.java:353)
    at NewJFrame.btn_refreshActionPerformed(NewJFrame.java:1140)
    at NewJFrame.access$1800(NewJFrame.java:47)
    at NewJFrame$21.actionPerformed(NewJFrame.java:734)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)

1 Answer 1

1

The same data should not be retrieved more than once from the result set.
Namely, because rs.getString(1) was executed twice, the exception was thrown.
Use another variable to keep the value of rs.getString(1)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.