Java DataSource getDataSource(String jndi)

Here you can find the source of getDataSource(String jndi)

Description

get Data Source

License

Open Source License

Declaration

static private DataSource getDataSource(String jndi) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import javax.sql.DataSource;

public class Main {
    static private DataSource getDataSource(String jndi) {
        javax.naming.Context initContext;
        try {//  w ww .  j av a 2s  . com
            initContext = new javax.naming.InitialContext();
            return (DataSource) initContext.lookup("java:comp/env/" + jndi);
        } catch (Exception ex) {
            //log.info(ex.toString());
            // try 
            try {
                initContext = new javax.naming.InitialContext();
                return (DataSource) initContext.lookup(jndi);
            } catch (Exception e) {
                System.err.println("Can't initialize resource " + jndi + "; not running in Tomcat/Jetty/Glassfish "
                        + "or other app container?");
                e.printStackTrace();
            }
        }
        return null;
    }
}

Related

  1. getConnection(CommonDataSource dataSource)
  2. getConnection(DataSource dataSource)
  3. getConnection(final DataSource ds, final boolean autoCommit)
  4. getConnectionFromDataSource(DataSource ds)
  5. getDatabaseName(DataSource dataSource)
  6. getDataSource(String jndiName)
  7. getDataSource(String service)
  8. getDataSourceCache(String hostName)
  9. getDBConnection(DataSource dataSource)