List of usage examples for javax.naming InitialContext InitialContext
public InitialContext() throws NamingException
From source file:Main.java
private Connection getConnection() { Connection connection = null; try {/* w w w.jav a 2s .com*/ InitialContext context = new InitialContext(); DataSource dataSource = (DataSource) context.lookup("jdbc/DataSource"); connection = dataSource.getConnection(); } catch (NamingException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } return connection; }
From source file:com.wso2telco.core.dbutils.DbUtils.java
/** * Initialize datasources.//from w ww .j av a 2 s . com * * @throws SQLException * the SQL exception * the db util exception */ public static void initializeDatasources() throws SQLException, DBUtilException { if (Datasource != null) { return; } try { log.info("Before DB Initialize"); Context ctx = new InitialContext(); DEP_DATA_SOURCE = (DataSourceNames.WSO2TELCO_DEP_DB.jndiName()); Datasource = (DataSource) ctx.lookup(DEP_DATA_SOURCE); } catch (NamingException e) { handleException("Error while looking up the data source: " + DEP_DATA_SOURCE, e); } }
From source file:hnu.helper.DataBaseConnection.java
/** Fetches new DataBaseConnection from Pool */ public Connection getDBConnection() { Connection conn = null;//from ww w .jav a 2 s . c o m try { Context ctx = new InitialContext(); DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/hnuDB"); conn = ds.getConnection(); } catch (Exception sqle) { log.error("Couln't get connection from DataSource", sqle); //sqle.printStackTrace(); } return conn; }
From source file:pt.sapo.pai.vip.VipServlet.java
@Override public void init() throws ServletException { super.init(); try {/*from www . j av a 2 s .c om*/ servers = ((String) new InitialContext().lookup("java:comp/env/servers")).split(","); } catch (NamingException ex) { throw new ServletException(ex); } }
From source file:TransformServlet.java
/** * Servlet initializer - look up the bean's home interface *///from w ww .j a va 2 s . c o m public void init(ServletConfig config) throws ServletException { try { InitialContext context = new InitialContext(); Object transformRef = context.lookup("transform"); transformer = (TransformHome) PortableRemoteObject.narrow(transformRef, TransformHome.class); } catch (Exception NamingException) { NamingException.printStackTrace(); } }
From source file:com.wso2telco.proxy.util.DBUtils.java
private static void initializeDatasource() throws NamingException { if (dataSource != null) { return;/*from ww w .jav a 2 s.co m*/ } String dataSourceName = null; try { Context ctx = new InitialContext(); dataSourceName = configurationService.getDataHolder().getMobileConnectConfig().getAuthProxy() .getDataSourceName(); if (dataSourceName != null) { dataSource = (DataSource) ctx.lookup(dataSourceName); } else { throw new ConfigurationException("DataSource could not be found in mobile-connect.xml"); } } catch (ConfigurationException e) { throw new ConfigurationException("DataSource could not be found in mobile-connect.xml"); } catch (NamingException e) { throw new NamingException("Exception occurred while initiating data source : " + dataSourceName); } }
From source file:io.apiman.gateway.engine.ispn.AbstractInfinispanComponent.java
/** * @return gets the cache/*from w ww. j av a 2s . co m*/ */ protected Cache<Object, Object> getCache() { if (cache != null) { return cache; } try { InitialContext ic = new InitialContext(); CacheContainer container = (CacheContainer) ic.lookup(cacheContainer); cache = container.getCache(cacheName); return cache; } catch (NamingException e) { throw new RuntimeException(e); } }
From source file:com.dattack.naming.StandaloneJndiTest.java
@Test public void testBind() { try {/*from ww w . j a v a 2 s. c om*/ final InitialContext context = new InitialContext(); final String name = getCompositeName("jdbc", "testBind"); final Object obj = new Integer(10); context.bind(name, obj); assertEquals(obj, context.lookup(name)); } catch (final NamingException e) { fail(e.getMessage()); } }
From source file:com.wso2telco.gsma.authenticators.dao.impl.AttributeConfigDaoImpl.java
private static void initializeConnectDatasource() throws NamingException { if (mConnectDatasource != null) { return;/*w w w. j ava2 s. co m*/ } String dataSourceName = null; try { Context ctx = new InitialContext(); ConfigurationService configurationService = new ConfigurationServiceImpl(); dataSourceName = configurationService.getDataHolder().getMobileConnectConfig().getDataSourceName(); mConnectDatasource = (DataSource) ctx.lookup(dataSourceName); } catch (NamingException e) { throw new ConfigurationException("DataSource could not be found in mobile-connect.xml:" + e); } }
From source file:com.stratelia.silverpeas.silverStatisticsPeas.control.AbstractSpringDatasourceTest.java
@AfterClass public static void tearDownClass() throws Exception { InitialContext ic = new InitialContext(); ic.unbind("java:/datasources/silverpeas-jdbc"); springContext.close();//from ww w.java 2 s.c o m DBUtil.clearTestInstance(); SimpleMemoryContextFactory.tearDownAsInitialContext(); }