我正在尝试将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();
但它在预先声明中破裂。 setBlob(4,blob)。我有点google并尝试下面的代码,但它在connection.createBlob()。
Blob blob = connection.createBlob();
blob.setBytes(1, bytes);
答案 0 :(得分:0)
尝试使用setBytes();
方法
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();