⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imagetest.java

📁 OBPM是一个开源
💻 JAVA
字号:
package cn.myapps.test;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.List;

import oracle.sql.BLOB;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import cn.myapps.base.dao.PersistenceUtils;

import junit.framework.TestCase;

public class ImageTest extends TestCase {
	Session session;

	protected void setUp() throws Exception {
		super.setUp();
		session = PersistenceUtils.currentSession();
	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}

	public void testSave() throws Exception {
		FileInputStream fis = new FileInputStream("f:/yoyoshow90.jpg");
		System.out.println(fis.available());
		byte[] image = new byte[fis.available()];
		fis.read(image);

		Transaction transaction = session.beginTransaction();
		Image imageVO = new Image("2", image);
		BLOB blob = BLOB.empty_lob();
		blob.setBytes(0, image);
		imageVO.setImage2(blob);
		
		session.save(imageVO);
		transaction.commit();
	
		
	}

//	 public void testQuery() throws Exception {
//		Query query = session.createQuery("FROM Image WHERE id='1'");
//		Image imageVO = (Image) query.uniqueResult();
//		byte[] image = imageVO.getImage();
//		System.out.println(image.length);
//		FileOutputStream fos = new FileOutputStream("f:/yoyoshow90_tmp.jpg");
//		fos.write(image);
//		fos.close();
//	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -