我想要的byte []轉換成二進制大對象的Java BLOB轉換。我的代碼如下的byte [],使用PreparedStatement和sqllite
byte [] hashValue = HashClass.hash256Bytes(messageValue);
//query = "insert into message values (?)";
connection = ConnectionFactory.getConnection();
//Blob blob = new javax.sql.rowset.serial.SerialBlob(hashValue);
Blob blob = new SerialBlob(hashValue);
//blob.setBytes(1, hashValue);
preStatement = (PreparedStatement)
connection.prepareStatement(query);
preStatement. setBlob(1, blob);
rs = preStatement.executeQuery();
但它在預先聲明中斷。 setBlob(4,blob)。我已經做了谷歌並嘗試下面的代碼,但它給null null connection.createBlob()。
Blob blob = connection.createBlob();
blob.setBytes(1, bytes);
你試過只是調用'preStatement.setBytes(1字節)'? http://stackoverflow.com/questions/6090170/cannot-save-image-as-blob-to-sqlite爲什麼要擔心256字節的BLOB? – Thilo
在connection.createBlob()處添加堆棧跟蹤和查詢 – Jens
null。意味着連接不被創建。添加堆棧跟蹤或完整代碼 – dogant