通常情况下往数据库表里插入一条记录,每个字段的值我们都是用常量表示的.可是字节数组怎么样才能用常量表示呢?我的表里有三个字段,第一个是整型,后两个是字节数组(我用了blob类型,希望用来保存字节数组,不知道对不对.)现在我的表里有三个字段, SerialNo(整型), Certificate(Blob型), PublicKey(Blob型)
我想知道blob类型的字段能否保存字节数组,如果可以,我该怎么样插入一条记录.谢谢!
我想知道blob类型的字段能否保存字节数组,如果可以,我该怎么样插入一条记录.谢谢!
String str= "test string";
Byte [] b = str.getByte();
Hibernate b;
Blob bl = b.createBlob(b);
javax.sql.rowset.serial.SerialBlob(实现java.sql.Blob接口)里边有个SerialBlob(byte[] b)构造函数和setBytes方法。或者java.sql.PreparedStatement 里边有个setArray方法。
自己去看看吧。
byte[] cert=new byte[275];
byte[] publickey=nwe byte[300];str="insert into myTable(SerialNo, Certificate, PublicKey) values(..."stmt.executeQuery(str);怎么写好啊?
兄弟,救我啊!
byte[] cert=new byte[275];
byte[] publickey=nwe byte[300];str="insert into myTable(SerialNo, Certificate, PublicKey) values(?,?,?);";PreparedStatement pstmt = conn.prepareStatement(str);pstmt.setInt(1,serial);pstmt.setBytes(2,cert);pstmt.setBytes(3,publickey);ResultSet rst = pstmt.executeQuery();