Here you can find the source of getJNDIConnectionByContainer(String dataSource)
Parameter | Description |
---|---|
dataSource | a parameter |
public static Connection getJNDIConnectionByContainer(String dataSource)
//package com.java2s; import java.sql.Connection; import javax.naming.InitialContext; import javax.sql.DataSource; public class Main { /**//from w w w. j av a 2s .co m * GetConnection with jdbc/xxxDS * @param dataSource * @return */ public static Connection getJNDIConnectionByContainer(String dataSource) { try { Connection conn = null; InitialContext ctx = new InitialContext(); if (ctx != null) { Object o = ctx.lookup(dataSource); DataSource ds = (DataSource) o; conn = ds.getConnection(); } return conn; } catch (Exception e) { e.printStackTrace(); return null; } } }