Look up DataSource from InitialContext : DataSource « Database SQL JDBC « Java

Look up DataSource from InitialContext


import java.sql.Connection;

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

public class Main {
  public static void main(String[] argv) throws Exception {
    InitialContext init = new InitialContext();
    DataSource source = (DataSource) init.lookup("dsn");
    Connection connection = source.getConnection();
    System.out.println("Connect to " + connection.getCatalog() + " a success!");


Related examples in the same category

1.Setup mysql datasource
2.implements DataSource