public static SerialBlob JSONToBlob(JSONObject object) throws SQLException { String text = object.toString(); text = text == null ? "{}" : text; return new SerialBlob(text.getBytes()); } public static JSONObject blobToJSON(SerialBlob blob) throws SerialException, IOException, JSONException { InputStream result = blob.getBinaryStream(); String jsonString = new String(toByteArray(result)); return new JSONObject(jsonString); } private static byte[] toByteArray(InputStream result) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); int i; while(( i = result.read())== -1) { out.write(i); } return out.toByteArray(); }