Skip to main content

Dynamically created jdbc resource is not accessible. Is this a bug?

1 reply [Last post]
Joined: 2007-08-24

I am trying to dynamically create a jdbc resource and access it.
The resource gets created successfully however when I try to look it up using jndi.
I get the following exception.

[#|2007-09-18T14:12:51.818-0700|WARNING|sun-appserver9.1||_ThreadID=19;_ThreadName=httpSSLWorkerThread-8080-0;_RequestID=1f70f223-e144-4dd7-9c41-1898175da2ef;|javax.naming.NameNotFoundException: DB1 not found
at com.sun.enterprise.naming.TransientContext.doLookup(
at com.sun.enterprise.naming.TransientContext.lookup(
at com.sun.enterprise.naming.TransientContext.lookup(
at com.sun.enterprise.naming.SerialContextProviderImpl.lookup(
at com.sun.enterprise.naming.LocalSerialContextProviderImpl.lookup(
at com.sun.enterprise.naming.SerialContext.lookup(
at javax.naming.InitialContext.lookup(

I then tried a little experiment.
I logged into the admin console and deleted the jdbc/DB1 resource from it.
i recreated it using the admin console.
I ran my code again and this time the JNDI lookup succeeded.
Dynamically creating pools is essential for our application.
Is there something else that needs to be done in addition to what I am doing.

The following is my test code.

String connectionPoolName = "DB_DB1";
String resourceName = "jdbc/DB1";

try {
AppserverConnectionSource appserver =
new AppserverConnectionSource(AppserverConnectionSource.PROTOCOL_RMI, "localhost", 8686 , "admin", "adminadmin", null);

DomainRoot domainRoot = appserver.getDomainRoot();

//Its a 2 step process
//First create the pool
Map conPoolMap = domainRoot.getDomainConfig().getJDBCConnectionPoolConfigMap();
System.out.println("pool exists");
Map map = new HashMap();
map.put("property.user", "user");
map.put("ResType", "javax.sql.DataSource");
map.put("property.password", "password");
map.put("property.url", "url");

domainRoot.getDomainConfig().createJDBCConnectionPoolConfig(connectionPoolName, "oracle.jdbc.pool.OracleDataSource", map);

System.out.println("JDBC Pool : " + connectionPoolName + " created !");

//Second create the resource
Map resMap = (Map) domainRoot.getDomainConfig().getJDBCResourceConfigMap();
if (resMap.containsKey(resourceName))
System.out.println("JDBC Resource : " + resourceName + " already exists");
domainRoot.getDomainConfig().createJDBCResourceConfig(resourceName, connectionPoolName, null);
System.out.println("JDBC Resource : " + resourceName + " created !");
InitialContext ic = new InitialContext();

} catch (IOException e) {
// TODO Auto-generated catch block
catch (NamingException e)
// TODO Auto-generated catch block

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2005-04-13

Do you have resource-ref created for the resource for particular target (eg: server )

Refer :