Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How do I use a pre-configured DataSource from Servlet?

0
Posted

How do I use a pre-configured DataSource from Servlet?

0

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) { …

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123