ITeye博客

tomcat websphere 从数据源中获取链接

wunda · 2011-05-17 16:27 · java · 企业架构 · Markdown

public boolean getConnection() {

	/**
	 * 连接池直接配置tomcat
	 */
	try {
		Context initCtx = new InitialContext();
		if (initCtx == null)
			throw new Exception("没有匹配的上下文环境");
		
		// tomcat 的连接方式。
		Context envCtx = (Context) initCtx.lookup("java:comp/env");
		DataSource ds = (DataSource) envCtx.lookup("jdbc/trms");
		// websphere 的连接方式。

// System.out.println("数据库链接前"); // DataSource ds = (DataSource) initCtx.lookup("jdbc/trms"); // System.out.println("数据库链接成功"); if (ds == null) throw new Exception("没有匹配的数据库"); conn = ds.getConnection(); conn.setAutoCommit(true); // conn=DriverManager.getConnection("proxool.connpool"); return true; } catch (Exception e) { // 系统异常记录日志 error = "《==tool/com.cncsi.dm.db.conn/dbConnect//数据库公共类处理异常==》"; UserException.error(error); UserException.error(e.toString()); e.printStackTrace(); return false; } }

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。