database) and this attribute's name along with the new value of the
attribute and the actor id will be passed to an "updateDatabase"function.
But how do i write a statement or preparedStatement when I don't know
beforehand what column is supposed to get changed?
If I knew the attribute I would write
update actor set attributeName = newValue where actor_id = ?
Seems like you can write something like:
public void updateDatabase(String aName, String aValue, int actorId)
throws SQLException
{
PreparedStatement ps = conn.prepareStatement(
"update actor set " + aName + "=? where actor_id = ?");
ps.setString(1, aValue);
ps.setInt(2, actorId);
ps.executeUpdate();
ps.close();
conn.commit();
}
Note that by using a prepared statement and a '?' for the attribute
value, you don't have to hassle with quotation marks around the value.
thanks,
bryan