I have a problem with a database right now. There is a BLOB field in the database. The BLOB is an XML. In this BLOB I have to update the XML.
However, I have no idea how to do this. Unfortunately, databases are not my strong point.
My method so far looks like this:
public void UpdateCharacterData(long characterID, long oid, String name, String xmlData) {
String sql = "SELECT data FROM objstore WHERE obj_id=? AND namespace_int=? AND type=? AND name=?";
//String sql = "UPDATE data FROM objstore WHERE obj_id=? AND namespace_int=? AND type=? AND name=?";
try (PreparedStatement ps = queries.prepare(sql)) {
ps.setLong(1, characterID);
ps.setInt(2, 3);
ps.setString(3, "Player");
ps.setString(4, name);
try (ResultSet rs = queries.executeSelect(ps)) {
if (rs != null) {
while (rs.next()) {
String data = rs.getString("data");
Log.debug(data);
}
}
}
} catch (SQLException ex) {
ex.printStackTrace();
Log.dumpStack("SQLException: " + ex);
}
}
So I would have to read out the BLOB completely and convert it to XML. Make my changes and then write them back. At least that's my guess.
I hope someone can help me further.
Thank you!