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
我试图将DB值存储到两个不同的数组中。如果test_type是“New”=>存储第一个数组,则=>第二个数组。在将rs.getString值分配给变量\ array时,得到“SEVERE:null java.sql.SQLException:No data found error”。谁能帮我解决这个问题?我使用MS访问作为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 个解决方案
#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)
不应从结果集中多次检索相同的数据。也就是说,因为rs.getString(1)被执行了两次,所以抛出了异常。使用另一个变量来保持rs.getString(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)
不应从结果集中多次检索相同的数据。也就是说,因为rs.getString(1)被执行了两次,所以抛出了异常。使用另一个变量来保持rs.getString(1)的值