public class FileUploadDownLoadDAO extends JdbcDaoSupport {
public void saveFile(final int viewid, final int voutableId,
final String contentStr,final String fileName) throws SQLException, IOException {
String insertSql = "insert into IFMIS_T_UPLOADFILE(VIEWID,VOUTABLEID,FILECONT,FILENAME) values(?,?,?,?)";
final OracleLobHandler lobHandler = new OracleLobHandler();
lobHandler.setNativeJdbcExtractor(new CommonsDbcpNativeJdbcExtractor());
this.getJdbcTemplate().execute(insertSql,
new AbstractLobCreatingPreparedStatementCallback(lobHandler) {
protected void setValues(PreparedStatement ps,
LobCreator lobCreator) throws SQLException {
ps.setInt(1, viewid);
ps.setInt(2, voutableId);
lobCreator.setClobAsString(ps, 3, contentStr);
ps.setString(4, fileName);
}
});
}
public Map getFileContentById(Integer viewid, Integer voutableId)
throws AppException {
final OracleLobHandler lobHandler = new OracleLobHandler();
lobHandler.setNativeJdbcExtractor(new CommonsDbcpNativeJdbcExtractor());
String sql = "select FILECONT,FILENAME from IFMIS_T_UPLOADFILE where VIEWID=? and VOUTABLEID=?";
Object[] objs = new Object[] { viewid, voutableId };
int[] types = new int[] { Types.INTEGER, Types.INTEGER };
List list = null;
Map map = new HashMap();
list = getJdbcTemplate().query(sql, objs, types, new RowMapper() {
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
Map map = new HashMap();
// 字段名
String filestr = lobHandler.getClobAsString(rs, "FILECONT");
String fileName = rs.getString("FILENAME");
map.put("filestr", filestr);
map.put("fileName", fileName);
return map;
}
});
// System.out.println("---------->filestrz= "+(String) list.get(0));
if(null != list && list.size() > 0)
map = (Map) list.get(0);
return map;
}