获取SEVERE:null java.sql.SQLException:未找到数据错误

时间:2015-05-04 03:12:32

标签: java sql sqlexception

我正在尝试将DB值存储到两个不同的数组中。如果test_type是“New”=>存储第一个数组,else =>第二阵列。在将rs.getString值分配给变量\ array时,得到“SEVERE:null java.sql.SQLException:No data found error”。谁能帮我解决这个问题?我使用MS访问作为DB

代码:

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++;
    }  

错误:

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 个答案:

答案 0 :(得分:1)

不应从结果集中多次检索相同的数据 也就是说,因为rs.getString(1)被执行了两次,所以抛出了异常 使用其他变量来保留<a href="pageb.html#check1" checked>Link to check Checkbox1</a> <a href="pageb.html#check2" checked > Link to Check Checkbox2</a> 的价值