Hi:
I’ve written my own code to try to get access to the JNDI database connection within an uberJar. I have declared my jetty-env.xml with the default cuba datasource JNDI name jdbc/CubaDS. My app works, except when I try to access the JNDI connection myself. Here’s the jetty-env.xml:
<?xml version="1.0"?>
<!--
~ (C) 2019 Professional Advertising Systems Inc.
-->
<!DOCTYPE Configure PUBLIC "-" "http://www.eclipse.org/jetty/configure_9_0.dtd">
<Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext">
<New id="CubaDS" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg/>
<Arg>jdbc/CubaDS</Arg>
<Arg>
<New class="org.apache.commons.dbcp2.BasicDataSource">
<Set name="driverClassName">org.postgresql.Driver</Set>
<Set name="url">jdbc:postgresql://postgres.paslists.com/pas</Set>
<Set name="username"><SystemProperty name="app.rade.user"/></Set>
<Set name="password"><SystemProperty name="app.rade.pwd"/></Set>
<Set name="maxIdle">2</Set>
<Set name="maxTotal">20</Set>
<Set name="maxWaitMillis">5000</Set>
</New>
</Arg>
</New>
</Configure>
Here’s the code that tries to get the connection info:
DataSource ds;
Connection conn=null;
String connStr;
if (parameterMap.containsKey("conn")) {
connStr = (String) parameterMap.get("conn");
} else {
connStr = "java:comp/env/jdbc/CubaDS";
}
try {
Context ctx = new InitialContext();
ds = (DataSource) ctx.lookup(connStr);
conn = ds.getConnection();
} catch (Exception e) {
e.printStackTrace();
}
I am able to get the ctx:
Then, when I try to look up the datasource with ctx.lookup(connStr), I get the following exception (jdbc name is not bound):
Any idea why I can’t look up the connection? What am I missing here?
Thanks in advance for any help you can provide.