讀取數據庫中BLOB字段

@Override
	public String getFormViewById(final String id) {
		return (String)getHibernateTemplate().execute(new HibernateCallback<Object>(){
			public Object doInHibernate(Session session) throws HibernateException, SQLException {
				String sql = "select formView from sys_forms where id='" + id + "'";
				Connection conn = null;
				PreparedStatement stmt = null;
				ResultSet rs = null;
				String content = "";
				try {
					conn = session.connection();
					stmt = conn.prepareStatement(sql);
					rs = stmt.executeQuery();
					while(rs.next()){
						Blob blob = (Blob) rs.getBlob("formView");  
						int bolblen = (int) blob.length();  
						byte[] data = blob.getBytes(1, bolblen);  
						content = new String(data,"utf-8");
					}
				}finally{
					conn.close();
					stmt.close();
				}
				
				return content;
			}
		});
	}


發佈了14 篇原創文章 · 獲贊 0 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章