如何在java中将Jsonnode转换为Blob?

时间:2016-09-21 20:38:19

标签: java blob

我有一个Jsonnode对象,如果将其转换为字符串,它将如下所示:

{"id": "A1", "address":"xxxx", "loginhistory":[{"ip":"xxx", "time":"xxx},{"ip":"xxx", "time":"xxx}] }

我尝试将其转换为blob,我目前编写的代码如下:

Jsonnode node = ....;
String s = mapper.writeValueAsString(node);
String sql = "UPDATE users "
            + "SET info = ? "
            + "WHERE UserName = ?";
PreparedStatement statement = connection.prepareStatement(sql)) {
                Blob blob = connection.createBlob();
                blob.setBytes(1, s.getBytes(Charset.forName("UTF-8")));
                statement.setQueryTimeout(timeout);
                statement.setBlob(1, blob);
                statement.setString(2, username);
                statement.executeUpdate();
}

我希望info是blob,但看起来我将其更新为字符串(如我给出的字符串示例)。任何人都可以教我如何将Jsonnode转换为Blob?

0 个答案:

没有答案