Package Jdbc.datasource; /** * Customizing a connection Pool * Note: The Create connection pool must implement Java-given DataSource interface, and other vendors must implement the given interface * @author Administrator/import Java.io.Pr
Intwriter;
Import java.sql.Connection;
Import java.sql.SQLException;
Import java.sql.SQLFeatureNotSupportedException;
Import java.util.LinkedList;
Import Java.util.logging.Logger;
Import Javax.sql.DataSource;
Import jdbc.utils.JDBCUtils_V3; public class myDataSource implements datasource{//1. The first step is to create a LinkedList collection for storing the created connection object private static linkedlist<
Connection> connpool=new linkedlist<> ();
2. Keep 5 connection objects in the pool static {for (int i=0;i<5;i++) {Connpool.add (jdbcutils_v3.getconnection ()); }/** * Rewrite getconnection () method * * @Override public Connection getconnection () throws SQLException {Connection Co
Nn=null; 3. Before getting the connection, first determine if there is a connection in the pool of connections if (Connpool.size () ==0) {for (int i=0;i<5;i++) {Connpool.add (Jdbcutils_v3.getconnec
tion ());
}//4. Deletes from the connection pool and returns the first connection Conn=connpool.remove (0);
Return conn; /** * A method of returning a connection created by itself * @param conn/public void Givebackconnection (Connection conn) {CONNPOOL.ADD (conn);
@Override public PrintWriter Getlogwriter () throws SQLException {return null; @Override public void Setlogwriter (PrintWriter out) throws SQLException {} @Override public void setLoginTimeout
(int seconds) throws SQLException {} @Override public int getlogintimeout () throws SQLException {return 0;
@Override public Logger Getparentlogger () throws sqlfeaturenotsupportedexception {return null;
@Override public <T> T Unwrap (class<t> iface) throws SQLException {return null;
@Override public boolean iswrapperfor (Class<?> iface) throws SQLException {return false; @Override Public Connection getconnection (string Username, string password) throws SQLException {return null
;
}
}