|
/**
* 描述: 添加某张表某条记录的content字段,此字段为 blob 型
* param: 表名;主键;数据;数据库连接
* return: 添加成功返回 true ;否则返回 false
* */
public static boolean setBlob(String tableName,int>
Statement statement = null;
ResultSet ret = null;
String insertBlob = "select content from " + tableName + " where>
boolean flg = false;
try {
statement = conn.createStatement();
ret = statement.executeQuery(insertBlob);
oracle.sql.BLOB blob = null;
if (ret.next()) {
blob = ((OracleResultSet) ret).getBLOB(1);
}
OutputStream outstream = blob.getBinaryOutputStream();
byte[] data1 = data.getBytes();
outstream.write(data1, 0, data1.length);//就是这个地方出了问题,如果是修改,之前就有了长度为100字节的数据,而这次修改只有50字节数据,那么后面50个字节就不会被修改,仍然存在数据库中
outstream.flush();
outstream.close();
flg = true;
} catch (SQLException e1) {
e1.printStackTrace();
flg = false;
} catch (IOException e1) {
e1.printStackTrace();
flg = false;
} finally {
try {
if(statement != null) {
statement.close();
}
if(ret != null) {
ret.close();
}
}catch(Exception ex) {
ex.printStackTrace();
}
}
return flg;
}
|
|
|