用LobHandler读写数据库lob字段

写:

 

public void insertSnap (final Map<String, String> map) throws DataAccessException {
		final String snapID = idGenUtil.getId("SY_I2_SNAP", "SNAP", map.get("submitorDept"));
		
		String sql = "INSERT INTO SY_I2_SNAP(SNAP_ID, SNAP_TITLE, SNAP_CONTENT, SNAP_SUBMITOR, SUBMITOR_DEPT) " +
				" VALUES(?,?,?,?,?)";
		
		this.getJdbcTemplate().update(sql, new PreparedStatementSetter() {
			public void setValues (PreparedStatement pst) throws SQLException {
				pst.setString(1, snapID);
				pst.setString(2, map.get("snapTitle"));
				lobHandler.getLobCreator().setClobAsString(pst, 3, map.get("snapContent"));

				pst.setString(4, map.get("snapSubmitor"));
				pst.setString(5, map.get("submitorDept"));
			}
		});
	}

 

 

读:

public String loadSnap (final String snapID) {
		
		String sql = "SELECT SNAP_CONTENT FROM SY_I2_SNAP WHERE SNAP_ID='"+snapID+"'";
		
		return (String) this.getJdbcTemplate().query(sql,
			new ResultSetExtractor() {

				public Object extractData(ResultSet rs) throws SQLException,
						DataAccessException {
					rs.next();
					return lobHandler.getClobAsString(rs, 1);

				}
				
			});
		
	}
 

 

 

你可能感兴趣的:(sql)