my dog learned polymorphism*
The moose likes Websphere and the fly likes Problem getting pooled connection to zOS database from Win2000 WAS 7.0 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Websphere
Bookmark "Problem getting pooled connection to zOS database from Win2000 WAS 7.0" Watch "Problem getting pooled connection to zOS database from Win2000 WAS 7.0" New topic
Author

Problem getting pooled connection to zOS database from Win2000 WAS 7.0

Bruce Alvarez
Greenhorn

Joined: Mar 24, 2010
Posts: 1
Good day all and thanks for all the solutions I have found here in the past through Google!

I receive the error: "javax.naming.NamingException:Attempted to use a 4.0 DataSource from a 2.3 (or higher) servlet. Invalid configuration." trying to get a pooled connection to a DB2 install on a zOS (MVS) server. The pooled connections to data sources on remote DB2 V8.2 installs on Windows work fine. Sadly, the only references I've found to this error were a suggestion to use a Version 5 DataSource and a list of WAS messages including this one.

Failing environment is WAS 6.1 in RAD 7.0 (same failure in WAS 7.0 with EAR exported from RAD 7.0).
The code previously generated with WSAD 5.1 ran on WAS 6.1 (yeah, I'm slow on the upgrades). I recognize that RAD 7 is using newer Servlet levels but AFAIK, there is no WAS DataSource higher than 4.0. Shouldn't it work with servlet levels > 2.2?? The "Test Connection" works in both production WAS 7 and within the RAD 7.0 test WAS 6.1 server Admin Consoles using a Component Managed Authentication alias.

When I set the UNIVERSAL_JDBC_DRIVER_PATH WebSphere variable, the error changed to
"An attempt was made to access a database, <database>, which was not found.". Certainly the database exists, I can connect to it via the Admin console, it is defined the same way as I define it in the DB2 Configuration Assistant.
When I change the code to call a method that does not use pooled connections, it works.


The code:

static {
try {
Class.forName("com.ibm.db2.jcc.DB2Driver").newInstance();
} catch (Exception e) {...}
}
static {
try {
Class.forName("com.ibm.db2.jcc.DB2ConnectionPoolDataSource").newInstance();
} catch (Exception e) {...}
}


Pooled connection method (failing on the ctx.lookup call):
(sSource is in the format: jdbc/dataSourceName - defined in the WAS Server as a Type 4 connection using the DB2 Universal data store helper as are all my Windows server based databases)

public Connection getPooledConnection(String sSource, String sUser, String sPW) {
Connection conn = null;
DataSource ds = null;

try {
Hashtable<String, String> parms = new Hashtable<String, String>();
parms.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory" );
Context ctx = new InitialContext(parms);
DataSource ds = (DataSource) ctx.lookup(sSource);
} catch .....
}

if (ds != null) {
try {
conn = ds.getConnection( sUser, sPW );
} catch ... {
}
}
return conn;
}

error messages:

Context implementation: com.ibm.ws.naming.jndicos.CNContextImpl
Context method: lookupExt
Context name: Node01Cell/nodes/Node01/servers/server1
Target name: jdbc/db2adm
Other data: ""
Exception stack trace: com.ibm.websphere.naming.CannotInstantiateObjectException: Exception occurred while the JNDI NamingManager was processing a javax.naming.Reference object. [Root exception is javax.naming.NamingException: Attempted to use a 4.0 DataSource from a 2.3 (or higher) servlet. Invalid configuration.]


The method that doesn't use connection pooling AND works:

public Connection dbConnect( String sServerName, String sDb, String sUserId, String sPassword)
String dbURL = "jdbc:db2://" + sServerName + ":50000/" + sDb;
// sServerName is a Windows 2000 server install with Enterprise DB2 V8.2.
// This server also hosts the 'local' databases I use.
// The database name (sDb) is the ODBC data source name from the DB2 Configuration Assistant definition
try {
conn = DriverManager.getConnection( dbURL, sUserId, sPassword );
} catch..... {
}
}

Can anyone help me with this? I can change all my code that accesses host databases to not use connection pooling, but that would be some large amount of work, inefficient with respect to DB connections and shouldn't be necessary (at least I don't THINK it should) since it worked in prior versions of WAS.

Thanks


Bruce
 
 
subject: Problem getting pooled connection to zOS database from Win2000 WAS 7.0
 
Similar Threads
connecting to DB2 database from IRAD 6.0
problem in connecting struts to ejb
Content.INITIAL_CONTEXT_FACTORY
Help: WSAD DataSource Problem
Error in downloading ZipoutputStream