例: package servlet; import javax.naming.Context; import javax.sql.DataSource; import javax.naming.InitialContext; //import org.apache.log4j.Logger; import org.apache.*; import java.sql.*; public class Dbconn{ //private static Logger log=Logger.getLogger(Dbconn.class); public static Connection conn = null; public Context initCtx = null; public static Connection getConn() { try { conn = DriverManager.getConnection("proxool.cityrcPool"); if(conn==null){System.out.print("+++++++++++++++++++++++");}else{ System.out.print("________________________"); } //log.info("============获取Connection==========="); } catch (Exception e) { //log.info("============不能获取Connectiot========"); e.printStackTrace(); } finally{ } return conn; } } 我在另一个类中: import servlet.*; 我就可以调用了: Connection con=Dbcon.getConn()