当前位置: 技术问答>java相关
高手请看:如何用java存取DB2中的BLOB字段!!
来源: 互联网 发布时间:2015-06-24
本文导语: 最好举个例子! | 主要是用流操作。例如: // 假设你的数据库表名为 yourTableName 字段有 idPK 和 BlobColum // suppose the database drive you use support PreStatement! String strSqlTmp = "insert into yourTabl...
最好举个例子!
|
主要是用流操作。例如:
// 假设你的数据库表名为 yourTableName 字段有 idPK 和 BlobColum
// suppose the database drive you use support PreStatement!
String strSqlTmp = "insert into yourTableName (idPK,BlobColum) values(?,?)"
PreparedStatement sql = stmtInitedBefore.createPreStatement(strSqlTmp);
sql.setInt(1,nIdInitedBefore);
sql.setBinaryStream(2,(new ByteArrayInputStream(braInitedBefore)),braInitedBefore.length); // braInitedBefore is byte[] type! it is you buffer
stmtInitedBefore.executePrpUpdate();
//供参考!
// 假设你的数据库表名为 yourTableName 字段有 idPK 和 BlobColum
// suppose the database drive you use support PreStatement!
String strSqlTmp = "insert into yourTableName (idPK,BlobColum) values(?,?)"
PreparedStatement sql = stmtInitedBefore.createPreStatement(strSqlTmp);
sql.setInt(1,nIdInitedBefore);
sql.setBinaryStream(2,(new ByteArrayInputStream(braInitedBefore)),braInitedBefore.length); // braInitedBefore is byte[] type! it is you buffer
stmtInitedBefore.executePrpUpdate();
//供参考!
|
用stream
|
和Oracle中的取法应该差不多吧,你搜一下本论坛的BLOB应该就知道了。