Reputation: 1984
I'm having difficulty getting a JDBC DataSource using Tomcat 7
javax.naming.NameNotFoundException: Name [jdbc/weblogin01b] is not bound in this Context. Unable to find [jdbc].
at org.apache.naming.NamingContext.lookup(NamingContext.java:818)
at org.apache.naming.NamingContext.lookup(NamingContext.java:166)
at org.apache.naming.factory.ResourceLinkFactory.getObjectInstance(ResourceLinkFactory.java:92)
at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321)
at org.apache.naming.NamingContext.lookup(NamingContext.java:841)
at org.apache.naming.NamingContext.lookup(NamingContext.java:152)
at org.apache.naming.NamingContext.lookup(NamingContext.java:829)
at org.apache.naming.NamingContext.lookup(NamingContext.java:166)
In CATALINA_BASE/conf/server.xml
I have included a variety of slightly different resources all aiming to be the same connection hopefully one of them will be right:
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
<Resource name="jdbc/weblogin01"
username="weblogin01"
password="xxxxx"
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.pool.OracleDataSource"
description="Global Address Database"
url="jdbc:oracle:thin:@10.15.120.29:1522:DGSPC"
maxActive="15"
maxIdle="3" />
<Resource name="jdbc/weblogin01b"
user="weblogin01"
password="xxxxx"
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.OracleDriver"
factory="oracle.jdbc.pool.OracleDataSourceFactory"
url="jdbc:oracle:thin:@10.15.120.29:1522:DGSPC"
maxActive="20"
maxIdle="3"
maxWait="-1" />
<Resource name="jdbc/weblogin01c"
user="weblogin01"
password="xxxxx"
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@10.15.120.29:1522:DGSPC"
maxActive="20"
maxIdle="3"
maxWait="-1" />
</GlobalNamingResources>
In META-INF/context.xml
I have a ResourceLink to each resource
<Context antiJARLocking="true" path="/testDbAccess">
<ResourceLink name="jdbc/weblogin01"
global="jdbc/weblogin01"
type="javax.sql.DataSource"/>
<ResourceLink name="jdbc/weblogin01b"
global="jdbc/weblogin01b"
type="javax.sql.DataSource"/>
<ResourceLink name="jdbc/weblogin01c"
global="jdbc/weblogin01c"
type="javax.sql.DataSource"/>
</Context>
In web.xml I made no changes related to JDBC on the understanding that
the ResourceLink elements will be sufficient.
In Java code I try to get a DataSource as follows:
String dbUser = "weblogin01b";
try {
// Obtain our environment naming context
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
// Look up our data source
ds = (DataSource) envCtx.lookup("jdbc/" + dbUser);
if (ds == null) {
logger.log(Level.WARNING,"Null datasource for " + dbUser);
}
}
Given the exception above, it never gets a DataSource, this is the same for:
jdbc/weblogin01
jdbc/weblogin01b
jdbc/weblogin01c
I'm finding Tomcat an uphill struggle, any help would be much appreciated.
Upvotes: 2
Views: 4009
Reputation: 1984
Part 2 of the puzzle is solved:
That should be:
username="weblogin01"
NOT
user="weblogin01"
Upvotes: 1
Reputation: 1984
Part 1 of the puzzle is solved:
I was editing the wrong copy of server.xml
I am running Tomcat under NetBeans which makes a separate copy of CATALINA_HOME which it configures as CATALINA_BASE, I had not noticed the separate copy.
I wish Tomcat's CATALINA_HOME and CATALINA_BASE were always separate and distinctly different, i.e. no duplication of files.
Part 2 is a different story:
java.sql.SQLException: ORA-01017: invalid username/password; logon denied
I know that I've specified the correct username and password but I'm not seeing these values logged anywhere, I'm guessing that I've specified the correct values in the wrong properties.
Upvotes: 2