用数据库链接池的程序怎么改写成用javabean的呢?
代码如下 想改成 javaBean 连接的
package msdn.javabean;
import java.sql.*;
import javax.naming.*;
import javax.sql.*;
import sun.jdbc.rowset.*;
/**
* <p> Title: 基础数据库操作类 </p>
* <p> Description: </p>
* <p> Copyright: Copyright (c) 2006 </p>
* <p> Company: </p>
* @author hellion
* @version 1.0
*/
public class DBManager {
public static final String DATABASE = "java:comp/env/jdbc/database ";
public DBManager() {
}
/**
* 取数据库连接
* @param jndi 数据库连接JNDI
* @return 数据库连接
* @throws Exception
*/
public static Connection getConnection(String jndi) throws Exception {
Connection conn = null;
try {
Context initCtx = new InitialContext();
DataSource ds = (DataSource) initCtx.lookup(jndi);
conn = ds.getConnection();
conn.setAutoCommit(false);
}
catch (Exception e) {
e.printStackTrace();
}
return conn;
}
public static Connection getConnection() throws Exception {
return getConnection(DATABASE);
}
public static void cleanup(Connection conn, PreparedStatement ps) {
try {
if (ps != null) {
ps.close();
}
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (conn != null && !conn.isClosed()) {
conn.close();
}
}
catch (Exception e) {
e.printStackTrace();
}
}
protected static void cleanup(Connection c