我正在尝试将byte[]转换为blob。我的代码如下
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();
但是它在preStatement处断裂。setBlob (blob)。我做了一点谷歌,并尝试下面的代码,但它给空在connection.createBlob()。
Blob blob = connection.createBlob();
blob.setBytes(1, bytes);
try with setBytes();
method
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);
preStatement = (PreparedStatement) connection.prepareStatement(query);
preStatement. setBytes(1, hashValue);
rs = preStatement.executeQuery();