How do I use a pre-configured DataSource from Servlet?
Let us assume the DataSource name is OracleDS and the location is jdbc/OracleDS. These are defined in the j2ee/home/config/data-sources.xml file. The following code demonstrates how to lookup the DataSource and obtain a connection. try { InitialContext context = new InitialContext(); DataSource myDS = (DataSource) context.lookup(“jdbc/OracleDS”); Connection conn = myDS.getConnection(); … // Use connection as normal since it’s a normal JDBC connection } catch(NamingException ne) { …