basedao.java

来自「spring + ibatis + struts」· Java 代码 · 共 42 行

JAVA
42
字号
package stock.dao;

import java.io.Reader;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

public class BaseDao 
{
	private static final SqlMapClient sqlMapClient;
	static
	{
		try
		{
			String resource = "config/ibatis/sql-map-config.xml";
			Reader reader = Resources.getResourceAsReader(resource);
			sqlMapClient = SqlMapClientBuilder.buildSqlMapClient(reader);
		}
		catch (Exception e)
		{
			// If you get an error at this point, it matters little what it was.
			// It is going
			// to be
			// unrecoverable and we will want the app to blow up good so we are
			// aware of the
			// problem. You should always log such errors and re-throw them in
			// such a way
			// that
			// you can be made immediately aware of the problem.
			e.printStackTrace();
			throw new RuntimeException(
					"Error initializing MyAppSqlConfig class. Cause: " + e);
		}
	}

	public static SqlMapClient getSqlMapInstance()
	{
		return sqlMapClient;
	}
}

⌨️ 快捷键说明

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