📄 testloadblob.java
字号:
package main;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import test.hibernate.HibernateSessionFactory;
public class TestLoadBlob {
public static void main(String [] args)
{
// OutputStream out = null;
// Session s = null ;
// try
// {
// SessionFactory sf = new Configuration().configure().buildSessionFactory();
// s = sf.openSession();
// // Transaction tx = s.beginTransaction();
//
// //begin BlobTest
// Iricinfo blobtest = new Iricinfo();
// blobtest = (Iricinfo) s.load(Iricinfo.class, new Integer(1));
//
// //begin OutputStream
// out = new FileOutputStream("d:/xixi.zip");
// InputStream in=blobtest.getFILEINFO().getBinaryStream();
// byte[] b =new byte[in.available()];
// in.read(b);
// out.write(b);
// out.flush();
// out.close();
// }
// catch (Exception e)
// {
// e.printStackTrace();
// }
// finally
// {
// try
// {
// s.close();
// }
// catch (Exception e1)
// {
// e1.printStackTrace();
// }
// }
try{
// SessionFactory sf = new Configuration().configure().buildSessionFactory();
// Session session = sf.openSession();
// Session session = HibernateSessionFactory.getSession();
// Connection con = session.connection();
// con.setAutoCommit(false);
// PreparedStatement ps = null;
// String sql = "select fileinfo from Iricinfo where busdate='2007-06-06'";
//
// ps = con.prepareStatement(sql);
// ResultSet rs = ps.executeQuery();
// System.out.println("out");
// if (rs.next())
// {
// System.out.println("come in");
// java.sql.Blob blob = rs.getBlob(1);
// InputStream ins = blob.getBinaryStream();
//
// //鐢ㄦ枃浠舵ā鎷熻緭鍑烘祦
// File file = new File("d:/haha.zip");
// OutputStream fout = new FileOutputStream(file);
//
// //涓嬮潰灏咮LOB鏁版嵁鍐欏叆鏂囦欢
// byte[] b = new byte[1024];
// int len = 0;
// while ( (len = ins.read(b)) != -1)
// {
// fout.write(b, 0, len);
// }
// //渚濇
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -