Reputation: 303
I don't really know what is going on so I'll just post part of the code
int index2 = 0;
while(rs.next()){
System.out.println(rs.getInt("ItemID") + ", " + rs.getString("SocSecNum") + ", " + rs.getInt("Score"));
if(rs.getInt("ItemID") == ID && rs.getString("SocSecNum").equals(socSecNum)){
alreadySet = true;
System.out.println("Flag 1");
caq.executeUpdate("UPDATE ProjectScore SET Score = " + userScoreField.getText() +
" WHERE (ItemID = " + ID + ") AND (SocSecNum = '" + socSecNum + "')");
}
index2++;
System.out.println(index2);
}
System.out.println("Flag 2");
Looks like it would work yeah? Here's the output:
1, 640730-7419, 3
Flag 1
1
This would imply that the while-loop is stuck somehow but there is no additional output (index2). Also, the database is updated exactly as it should but the program doesn't progress from here and "Flag 2" is never written out. Any ideas?
Edit:
catch (SQLException e1) {
System.out.println(e1.getMessage());
System.out.println(e1.getCause());
}
Gives
Operation not allowed after ResultSet closed
null
Edit 2:
Here's the code used to make it work
PreparedStatement statement = caq.getConnection().prepareStatement("SELECT * FROM ProjectScore WHERE SocSecNum = '"
+ socSecNum + "'", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
rs = statement.executeQuery();
Upvotes: 0
Views: 1108
Reputation: 10997
can you try instead of caq.executeUpdate
connection.prepareStatement().executeUpdate()
I am assuming caq.executeUpdate
will cause the previous returned ResultSet object to close.
Also there seems to be a way to set concurrency level in Statement
ResultSet.CONCUR_UPDATABLE
http://docs.oracle.com/javase/6/docs/api/java/sql/Connection.html#prepareStatement(java.lang.String,int,int)
Upvotes: 1