InfoCenter Home >
3: Migration overview >
3.3: Migrating APIs and specifications >
3.3.8: Migrating to supported database connection APIs (and JDBC) >
3.3.8.2: Migrating servlets from the connection manager model
3.3.8.2: Migrating servlets from the connection manager model
Servlets written to use the connection manager
should continue to work in the Application Server Version
3.5 environment, provided that the servlets
use a subset of the connection manager APIs that
are deprecated but still supported.
See the Related information for the API subset, which is
anticipated to cover most existing servlets.
For most servlets, the migration
consists of simple code changes.
Because you should not write new servlets using the connection manager,
the details of connection manager coding
are not discussed, except as needed in the migration.
Migration involves the following activities.
For more details, see the related information.
Action needed |
From something like ... |
To something like ... |
Update import statements |
import java.sql.*;
import com.ibm.servlet.connmgr.*;
|
import javax.sql.*;
import javax.naming.*;
|
Modify servlet init() methods |
IBMConnSpec spec =
new IBMJdbcConnSpec("poolname", true,
"COM.ibm.db2.jdbc.app.DB2Driver",
"jdbc:subprotocol:database",
"userid", "password");
IBMConnMgr connMgr =
IBMConnMgrUtil.getIBMConnMgr();
|
Hashtable parms = new Hashtable();
parms.put(Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.ejs.ns.jndi.CNInitialContextFactory");
Context ctx = new InitialContext(parms);
DataSource ds =
(DataSource)ctx.lookup("jdbc/sample");
The WebSphere administrator provides information
on the arguments for the put() and lookup() methods.
|
Modifying how servlets obtain and close connections |
IBMJdbcConn cmConn =
(IBMJdbcConn)connMgr.getIBMConnection(spec);
Connection conn = cmConn.getJdbcConnection();
...
cmConn.releaseIBMConnection();
|
Connection conn =
ds.getConnection("userid", "password");
...
conn.close();
|
Modify preemption handling |
Call verifyIBMConnection()
|
Catch com.ibm.websphere.ce.cm.StaleConnectionException
|
Considerations for new servlets
The connection manager APIs are deprecated in the Application Server Version
3.5 environment and might not work with releases beyond this one.
You should not write new servlets using the connection manager. Instead,
write new servlets using the connection pooling model from Version 3.5.
|
|