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

📄 testblobdemo.java

📁 演示ibatis的基本使用方法
💻 JAVA
字号:
package learnBasic.simpleQuery;

import java.io.*;

import learnBasic.IBatisSqlMapClient;

import com.ibatis.dao.client.DaoManager;
import com.ibatis.sqlmap.client.*;



public class TestBlobDemo {
	SqlMapClient dataMapper = null;

	public TestBlobDemo() {
		dataMapper = IBatisSqlMapClient.getIBDataMapper();

	}

	public void DoTestInsertBlob(String DBType) {
		byte[] b = null;
		InputStream in = null;
		BlobDemo blobTest = null;
		try {
			//begin InputStream 
			in = new FileInputStream("d:/c.bmp");//b.jpg
			b = new byte[in.available()];
			in.read(b);
			in.close();
			System.out.println(b.length);
			//begin BlobTest
			blobTest = new BlobDemo();
			blobTest.setMyblob(b);

			dataMapper.startTransaction();
			dataMapper.insert(getInsertBlobKey(DBType), blobTest);
			dataMapper.commitTransaction();

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				dataMapper.endTransaction();
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		}
	}

	public void getBlob(String DBType) {
		OutputStream out = null;

		BlobDemo blobTest = null;
		try {
			//begin BlobTest
			blobTest = new BlobDemo();

			blobTest.setId(getTheLastedInsertId());

			//begin SqlMapClient
			blobTest = (BlobDemo) dataMapper
					.queryForObject(getBlobKey(DBType), blobTest);
			byte[] b = blobTest.getMyblob();

			//begin OutputStream
			out = new FileOutputStream("d:/c1.bmp");
			out.write(b);
			out.close();

			System.out.println(b.length);
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			
		}

	}
	
	public int getTheLastedInsertId() {
	
		BlobDemo blobTest = null;
		try {
			//begin BlobTest
			blobTest = new BlobDemo();
			
			//begin SqlMapClient
			blobTest = (BlobDemo) dataMapper
					.queryForObject("getTheLastedInsertId", blobTest);
			
			return blobTest.getId();
		} catch (Exception e) {
			e.printStackTrace();
			return 0;
		}

	}
	
	private String getBlobKey(String DBType){
		
		if ("ORACLE".equals(DBType))
			return "getOracleBlob";
		else if ("MYSQL".equals(DBType))
			return "getMySqlBlob";
		else
			return "";
	}
	
	private String getInsertBlobKey(String DBType){
		
		if ("ORACLE".equals(DBType))
			return "insertOracleBlob";
		else if ("MYSQL".equals(DBType))
			return "insertMySqlBlob";
		else
			return "";
	}
	
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		TestBlobDemo qy = new TestBlobDemo();
		qy.DoTestInsertBlob("ORACLE");
		qy.getBlob("ORACLE");
		
//		DaoManager daoMgr = DaoConfig.getDaoManager();
//		  AccountDao a = new AccountDao(daoMgr);
//		  a.getAccount("j2ee");
	}
}

⌨️ 快捷键说明

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