Java DataSource setUpJndiDatasource()

Here you can find the source of setUpJndiDatasource()

Description

set Up Jndi Datasource

License

Apache License

Declaration

public static void setUpJndiDatasource() 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import javax.naming.InitialContext;
import javax.sql.DataSource;

public class Main {
    private static final String DS_NAME = "ChinookDS";

    public static void setUpJndiDatasource() {
        try {//w  w  w .  j a  v a2s.c o  m
            InitialContext ctx = new InitialContext();
            DataSource ds = (DataSource) ctx.lookup("jdbc." + DS_NAME);
            // rebind for alias if needed
            ctx.rebind("java:/comp/env/jdbc/" + DS_NAME, ds);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

Related

  1. lookupDataSource(String dataSourceName, final Hashtable jndiProperties)
  2. myDataSource(String username, String password)
  3. purgeTables(DataSource ds)
  4. registerSpringDataSource(String name, DataSource dataSource)
  5. selectCount(DataSource ds, String tableName)
  6. sqlExe(DataSource dataSource, String sql)
  7. tableRecommendationExistsHsqdb(DataSource dataSource)
  8. update(DataSource dataSource, String sql, Object params[])
  9. update_Db(DataSource ds, String query)