從jndi獲取數據庫連接

public Connection getConnectionFromJNDI() {
		Connection conn = null;
		try {

			long t = System.currentTimeMillis();
			Context initCtx = new InitialContext();
			javax.sql.DataSource ds = (javax.sql.DataSource) initCtx.lookup("java:comp/env/" + JNDI_NAME);
			conn = ds.getConnection();
			t = System.currentTimeMillis() - t;
			_log.info("getConnectionFromJNDI " + t + "  ms");

			return conn;
		} catch (Exception e) {
			_log.error("getConnectionFromJNDI error " + e.getMessage(), e);
			e.printStackTrace();
			return null;
		}
	}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章