Первоначально я дал:
Statement replystmt = connection.createStatement;
который я изменил на
Statement replystmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet replyMessage = replystmt.executeQuery("SELECT * from REPLYMAIL where PARENTMESSAGEID = '" + parentMessage.getString("MESSAGEID") + "'");
Я все еще получаю следующую ошибку:
java.sql.SQLException: Invalid operation for forward only resultset : isLast
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.driver.OracleResultSetImpl.isLast(OracleResultSetImpl.java:390)
at inbox.InboxReader.getImportance(InboxReader.java:249)
at inbox.InboxReader.main(InboxReader.java:39)
Отредактировано:
static long getImportance(String username) throws Exception
{
Connection connection = connectToDatabase();
Statement parentstmt = connection.createStatement();
ResultSet parentMessage = parentstmt.executeQuery("SELECT * from MAIL");
long time1 = 0, sign = 0;
while(parentMessage.next())
{
System.out.println("Parent message : " + parentMessage.getString("MESSAGEID"));
int c = 0, evenc = 0;
String j = "";
Statement replystmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
//stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY)
ResultSet replyMessage = replystmt.executeQuery("SELECT * from REPLYMAIL where PARENTMESSAGEID = '" + parentMessage.getString("MESSAGEID") + "'");
if(!(parentMessage.getString("SENDERNAME").contains(username))) // When user receives a message first
{
while(replyMessage.next())
{
if(c==0) // for calculating the time between his reply time - message received time
{
time1 = replyMessage.getTimestamp("SENDDATE").getTime() - parentMessage.getTimestamp("RECEIVEDATE").getTime();
System.out.println("IF time in if c=0, " + time1);
c++;
sign = 1;
}
else
{
evenc++;
if(sign == 1) {
sign = -1;
j = "RECEIVEDATE";
System.out.println("IF receivedate : " + replyMessage.getTimestamp(j).getTime());
}
else if(sign != 1) {
sign = 1;
j = "SENDDATE";
System.out.println("IF senddate : " + replyMessage.getTimestamp(j).getTime());
}
if(replyMessage.isLast() && (evenc%2)!=0) {
System.out.println("IF skip");
}
else {
time1 = time1 + (sign * replyMessage.getTimestamp(j).getTime());
}
System.out.println("IF time in if c>0 , "+time1);
}
}
}
else { // When user sends a message first
sign = -1;
while(replyMessage.next()) {
evenc++;
if(sign == 1) {
sign = -1;
j = "RECEIVEDATE";
System.out.println("ELSE receivedate : " + replyMessage.getTimestamp(j).getTime());
}
else {
sign = 1;
j = "SENDDATE";
System.out.println("ELSE senddate : " + replyMessage.getTimestamp(j).getTime());
}
if(replyMessage.isLast() && (evenc%2)!=0) {
System.out.println("ELSE skip");
}
else {
time1 = time1 + (sign * replyMessage.getTimestamp(j).getTime());
}
System.out.println("ELSE time in if c>0 , "+time1);
}
}
}
connection.close();
return time1;
}
Как мне это исправить?
Спасибо!