Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning an updatable ResultSet object

Status
Not open for further replies.

koolraul

Programmer
Aug 20, 2003
10
US
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();
}
}
}
 
I got the answer from another Forum. Don't use '*' in the SELECT statement. Use the column names instead and it should work.
 
Or you could use the ResultSet.getString(int pos) method, or use the ResultSetMetaData to get the column names etc etc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top