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
must be modified to use WebSphere connection pooling.
For most servlets, the migration
consists of simple code changes.
Because new servlets cannot use 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.websphere.naming.WsnInitialContextFactory");
Context ctx = new InitialContext(parms);
DataSource ds =
(DataSource)ctx.lookup("java:comp/env/jdbc/SampleDB");
where SampleDB is the name of the data source.
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 not supported in the Application Server Version
4.0 environment.
You should not write new servlets using the connection manager. Instead,
write new servlets using the current connection pooling model.
|
|