Note that I cant change the type of column type (text) to any other type...
base64-encode it.
Code:
import java.util.prefs.Base64;
// ...
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oout = new ObjectOutputStream(baos);
oout.writeObject(obj);
oout.close();
ps.setBytes(1, Base64.byteArrayToBase64(baos.toByteArray()));
And:
Code:
byte[] buf = Base64.base64ToByteArray(new String(rs.getBytes(column)));
if (buf != null) {
ObjectInputStream objectIn = new ObjectInputStream(
new ByteArrayInputStream(buf));
Object obj = objectIn.readObject(); //Contains the object
PersonDetails p = (PersonDetails)obj;
System.out.println(p.getName()+"\t"+p.getAge()+"\t"+p.getSex());
}
However, using a binary column is preferable: base64-encoding can be inefficient.
Bookmarks