存储字节类型
public void updateDistributeSearchParams(final String id,
final ArrayList
String sql = " update ht_distribute_task set searchparamlist =
? where id = ? ";
this.getJdbcTemplate().execute(sql, new
AbstractLobCreatingPreparedStatementCallback(this.defaultLobHandler)
{
@Override
protected void setValues(PreparedStatement ps, LobCreator
lobCreator) throws SQLException, DataAccessException {
ByteArrayOutputStream baos = new
ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(searchParamList);
oos.close();
bytes = baos.toByteArray();
baos.close();
} catch (IOException e) {
e.printStackTrace();
}
lobCreator.setBlobAsBytes(ps, 1, bytes);
ps.setString(2, id);
}
});
}
public DistributeTask findDistributeTaskById(String id)
{
String sql = "select * from ht_distribute_task where id = ?
";
List taskList = this.getJdbcTemplate().query(sql, new
Object[]{id}, new DistributeTaskRowMapper());
if(taskList.size() > 0) {
DistributeTask t = taskList.get(0);
return t;
}
return null;
}
public class DistributeTaskRowMapper implements RowMapper
{
private Logger logger =
LoggerFactory.getLogger(DistributeTaskRowMapper.class);
private LobHandler defaultLobHandler;
@SuppressWarnings("unchecked")
@Override
public DistributeTask mapRow(ResultSet rs, int rowNum) throws
SQLException {
defaultLobHandler =
SpringContextHolder.getBean("defaultLobHandler");
DistributeTask task = new DistributeTask();
task.setId(rs.getString("id"));
task.setName(rs.getString("name"));
task.setOperateReason(rs.getString("operatereason"));
task.setTypeCode(rs.getInt("typecode"));
task.setRuleCode(rs.getInt("rulecode"));
task.setStatusCode(rs.getInt("statuscode"));
task.setSuccessResourceOperateable(rs.getBoolean("successresourceoperateable"));
task.setAsync(rs.getBoolean("async"));
task.setSynCustomerIds(rs.getString("syncustomerids"));
task.setSearchSql(rs.getString("searchsql"));
task.setTargetCount(rs.getInt("targetcount"));
task.setEffectCount(rs.getInt("effectcount"));
task.setFinishCount(rs.getInt("finishcount"));
task.setTimerTaskStartTime(rs.getString("timertaskstarttime"));
task.setTimerTaskEndTime(rs.getString("timertaskendtime"));
task.setCreateUserId(rs.getString("createuserid"));
task.setCreateDate(rs.getTimestamp("createdate")); //
备注,这里千万不能用 rs.getDate() [返回的只有年月日]
task.setEffectiveMilsec(rs.getLong("effectivemilsec"));
task.setDurationMilsec(rs.getLong("durationmilsec"));
task.setModifyDate(rs.getTimestamp("modifydate"));
ArrayList
try { // 处理二进制数据
byte[] searchParamBytes = defaultLobHandler.getBlobAsBytes(rs,
"searchparamlist");
if(searchParamBytes != null) {
ObjectInputStream ois = new ObjectInputStream(new
ByteArrayInputStream(searchParamBytes));
searchParamList = ((ArrayList
ois.close();
}
} catch (Exception e) {
logger.error("JIANGRH_查询分配任务时,对任务数据中的二进制信息进行包装出现异常--"+e.getMessage(),
e);
}
task.setSearchParamList(searchParamList);
return task;
}
}