我正在尝试在我的 MemSQL 数据库中插入 blob。
这是我插入源代码的地方,因此我将其转换为 blob :
byte[] bytes = rs.getString(2).getBytes("utf-8");
Blob blob = insert.insertTableBinary(bytes);
这是我的 insertTableBinary 函数:
Blob blob = conn.createBlob();
blob.setBytes(1, bytes);
System.out.println(blob.length());
String sql = "INSERT INTO binaire(receipt) VALUES(\"" + blob + "\")";
executeSQL(sql);
return blob;
此时 blob.lenght 等于 1555 但是当我读到它时,感谢:
String sql2 = "SELECT * FROM binaire";
Statement st = conn.createStatement();
ResultSet rs2 = st.executeQuery(sql2);
while(rs2.next()) {
Blob blob = rs2.getBlob(1);
System.out.println(blob.length());
}
长度为25。奇怪的是,当我查看表中的数据时,我得到了:com.mysql.jdbc.Blob@6a8bc5d9
所以它不存储好东西不是吗?这是对对象的引用,但不是我认为的 blob。
但我不知道我做错了什么,我看到很多带有准备好的语句的例子,但这个功能在 MemSQL 中不可用