blob 액세스 그림clob 액세스 문자열

1629 단어 blob clob
Blob 바이너리 큰 객체 Clob 문자열 큰 객체

public void save(Login login,String loginPath,String description) throws IOException{
		
		InputStream in=this.getClass().getResourceAsStream(loginPath);
		byte[] buff=new byte[in.available()];
		in.read(buff);
		in.close();
		//       Blob  
		login.setImage(Hibernate.createBlob(buff));
		//   clob  
		login.setDescription(Hibernate.createClob(description));
		session=HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		session.save(login);
		session.getTransaction().commit();
	}
public void get(int id,String targetPath) throws SQLException, IOException{
		session=HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		Login login=(Login) session.get(Login.class, id);
		session.getTransaction().commit();
		//  Clob  
		Clob description=login.getDescription();
		Reader r=description.getCharacterStream();
		BufferedReader br=new BufferedReader(r);
		String desc=null;
		do {
			desc=br.readLine();
			if(desc==null)
				break;
			System.out.println(desc);
		} while (desc!=null);
		
		
		br.close();
		r.close();
		//Blob getBinaryStream()
		InputStream in=login.getImage().getBinaryStream();
		FileOutputStream out=new FileOutputStream(targetPath);
		byte[] buff=new byte[1024];
		while(in.read(buff)!=-1){
			out.write(buff);
		}
		out.close();
		in.close();
	}

좋은 웹페이지 즐겨찾기