Here you can find the source of setUpJndiDatasource()
public static void setUpJndiDatasource()
//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(); } } }