The variables TABLE_NAME and STD_NAME are both declared as
'private static final String'. I created the method
getUpdatableRS(Connection conn), which I'm expecting to
return an updatable ResultSet object. I created another
method, updStudentRowByName(ResultSet rset, String name) and passing the ResultSet object that I'm getting from the first method along with another parameter of String type.
Both of these methods are in my Student class. When I'm
calling both of these methods in my Database class in the main() method:
ResultSet rs = student.getUpdatableRS(conn);
student.updStudentRowByName(rs, "one"
;
I'm getting the error: 'java.sql.SQLException: Invalid operation for read only resultset: updateString'
It seems the it's telling me that the ResultSet object that
I'm getting is not updatable. Is this true? If it is, why
and how can I correct it? Thanks.
public ResultSet getUpdatableRS (Connection conn) throws SQLException {
String sql = "SELECT * FROM " + TABLE_NAME;
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rset = stmt.executeQuery(sql);
return rset;
}
public void updStudentRowByName (ResultSet rset, String name)
throws SQLException {
while(rset.next()) {
String rsName = rset.getString(STD_NAME);
if (rsName.trim().equalsIgnoreCase(name.trim())) {
String rsNewName = "New Name Of " + name;
rset.updateString(STD_NAME, rsNewName);
rset.updateRow();
}
}
}
'private static final String'. I created the method
getUpdatableRS(Connection conn), which I'm expecting to
return an updatable ResultSet object. I created another
method, updStudentRowByName(ResultSet rset, String name) and passing the ResultSet object that I'm getting from the first method along with another parameter of String type.
Both of these methods are in my Student class. When I'm
calling both of these methods in my Database class in the main() method:
ResultSet rs = student.getUpdatableRS(conn);
student.updStudentRowByName(rs, "one"
I'm getting the error: 'java.sql.SQLException: Invalid operation for read only resultset: updateString'
It seems the it's telling me that the ResultSet object that
I'm getting is not updatable. Is this true? If it is, why
and how can I correct it? Thanks.
public ResultSet getUpdatableRS (Connection conn) throws SQLException {
String sql = "SELECT * FROM " + TABLE_NAME;
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rset = stmt.executeQuery(sql);
return rset;
}
public void updStudentRowByName (ResultSet rset, String name)
throws SQLException {
while(rset.next()) {
String rsName = rset.getString(STD_NAME);
if (rsName.trim().equalsIgnoreCase(name.trim())) {
String rsNewName = "New Name Of " + name;
rset.updateString(STD_NAME, rsNewName);
rset.updateRow();
}
}
}