Skip to main content

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

1 reply [Last post]
roshan_ail
Offline
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|javax.enterprise.system.stream.err|_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(TransientContext.java:216)
at com.sun.enterprise.naming.TransientContext.lookup(TransientContext.java:188)
at com.sun.enterprise.naming.TransientContext.lookup(TransientContext.java:192)
at com.sun.enterprise.naming.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:74)
at com.sun.enterprise.naming.LocalSerialContextProviderImpl.lookup(LocalSerialContextProviderImpl.java:111)
at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:339)
at javax.naming.InitialContext.lookup(InitialContext.java:392)

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();
if(conPoolMap.containsKey(connectionPoolName))
{
System.out.println("pool exists");
}
else
{
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");
}
else
{
domainRoot.getDomainConfig().createJDBCResourceConfig(resourceName, connectionPoolName, null);
System.out.println("JDBC Resource : " + resourceName + " created !");
}
InitialContext ic = new InitialContext();
System.out.println(ic.lookup(resourceName));

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

Reply viewing options

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

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

Refer :
http://blogs.sun.com/JagadishPrasath/entry/creating_jdbc_connection_pool...