EJB访问数据库(场景2,使用JDBC 2.0) import java.sql.*; import javax.sql.*; // import here vendor specific JDBC drivers
public ProductPK ejbCreate() { try { // initialize JNDI lookup parameters Context ctx = new InitialContext(parms); ... ConnectionPoolDataSource cpds = (ConnectionPoolDataSource)ctx.lookup(cpsource); ... // Following parms could all come from a JNDI look-up cpds.setDatabaseName("PTDB"); cpds.setUserIF("XYZ"); ... PooledConnection pc = cpds.getPooledConnection(); Connection conn = pc.getConnection(); ... // do business logic conn.close(); } ... }