public void retriveRelevantDocument() throws SQLException, IOException {
byte data [] = new byte[]{};
File file =null ;
FileOutputStream fos = null;
InputStream in = null;
String fileName="aa.txt";
Session session = sessionFactory.openSession();
String s = "select relevant_document_content from relevantdocument where id='25'";
ResultSet rs = session.connection().prepareStatement(s).executeQuery();
while(rs.next()){
data = rs.getBytes(1);
}
file = new File("d:\\" + fileName);
if (!file.exists()) {
file.createNewFile(); // 如果文件不存在,则创建
}
fos = new FileOutputStream(file);
int size = 0;
if (data.length > 0) {
fos.write(data, 0, data.length);
} else {
while ((size = in.read(data)) != -1) {
fos.write(data, 0, size);
}
in.close();
}
fos.close();
session.close();
}