我正在尝试执行以下代码,但是正在显示" Exhausted Resultset"例外。我怎么能摆脱它?任何与此问题相关的帮助都将不胜感激......
这是Exception
我得到的......
java.sql.SQLException: Exhausted Resultset
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:199)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:263)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:271)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:445)
at oracle.jdbc.driver.OracleResultSetImpl.getString(OracleResultSetImpl.java:954)
at oracle.jdbc.driver.OracleResultSet.getString(OracleResultSet.java:494)
at ReadCol.data(ReadCol.java:47)
at ReadCol.main(ReadCol.java:71)
这是我的代码
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import javax.swing.JOptionPane;
public class ReadCol {
public String[] array;
public BufferedWriter out;
public int cnt = 0;
public void data() throws Exception{
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn= DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","System","mine");
conn.setAutoCommit(false);
Statement st=conn.createStatement();
ResultSet rs=st.executeQuery("select * from ATTENDANCE");
ResultSetMetaData rsmd = rs.getMetaData();
System.out.println("No of columns in the table:"+ rsmd.getColumnCount());
for (int i = 1; i <= rsmd.getColumnCount(); i++) {
String fname = rsmd.getColumnName(i);
System.out.println("COLUMN NAME: " + fname);
}
System.out.println();
while(rs.next()){
File file = new File("E:\\eclipse\\workspace\\AutoAttendanceSystem\\res\\AttendanceData.csv");
List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
for (String line : lines) {
array = line.split(",");
if( ( rs.getString(1) == null && array[0] == null || rs.getString(1) != null && rs.getString(1).equals(array[0]) ) && ( rs.getString(7) == null && array[6] == null|| rs.getString(7) != null && rs.getString(7).equals(array[6]) )){
JOptionPane.showMessageDialog(null, "Can't Update Because record already exist");
cnt++;
}
}
}
if(cnt == 0){
out.write(rs.getString("ATTENDANT_NAME") + ", ");
out.write(rs.getString("ATTENDANT_AGE") + ", ");
out.write(rs.getString("ATTENDANT_CONTACT_NO") + ", ");
out.write(rs.getString("ATTENDANT_DEPARTMENT_NAME") + ", ");
out.write(rs.getString("REGISTRATION_NUM") + ", ");
out.write(rs.getString("ABSENT_PRESENT") + ", ");
out.write(rs.getString("ATTENDANCE_TIME_DATE") + ", ");
out.newLine();
out.flush();
System.out.println("updated, not already Exist");
JOptionPane.showMessageDialog(null, "Updated");
}
out.close();
conn.close();
}catch (IOException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception{
ReadCol r = new ReadCol();
r.data();
}
}