public class DBConnectionPoolManager {
private Hashtable<String, DBConnectionPool> ht = new Hashtable<String, DBConnectionPool>();
private static DBConnectionPoolManager instance;
private String configfilePath="";    public static synchronized DBConnectionPoolManager getInstance() {
if (instance == null) {
instance = new DBConnectionPoolManager();
}

return instance;
}
        //以下两个成员函数有意义吗? 
        public String getConfigfilePath() {
return configfilePath;
} public void setConfigfilePath(String configfilePath) {
this.configfilePath = configfilePath;
}}我在另外的地方写如下代码:
DBConnectionPoolManager.getInstance();//这样写没问题
DBConnectionPoolManager.getInstance().setConfigfilePath()//不能调用这个成员函数。
所以想问问大家,问题出在哪个地方

解决方案 »

  1.   

    DBConnectionPoolManager.getInstance().setConfigfilePath()/
    没有定义无参数的set方法
      

  2.   


    赞成.
    DBConnectionPoolManager.getInstance().setConfigfilePath("abc");这样就没问题啊.
      

  3.   

    DBConnectionPoolManager.getInstance().setConfigfilePath("abc");
      

  4.   

    大家的理角可能出现偏差了,我不会犯这样低级错误
    DBConnectionPoolManager.getInstance().setConfigfilePath("abc");这里面的值,发贴时是我特意没写的。
    ----------------------------------------------------------------------------------------package com.lin.db;import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.sql.Connection;
    import java.util.Enumeration;
    import java.util.Hashtable;
    import java.util.Properties;public class DBConnectionPoolManager {
    private Hashtable<String, DBConnectionPool> ht = new Hashtable<String, DBConnectionPool>();
    private static DBConnectionPoolManager instance;
    private String configfilePath; private DBConnectionPoolManager() {
    this.configfilePath=System.getProperty("user.dir");
    init();
    }

    private DBConnectionPoolManager(String path) {
    this.configfilePath=path;
    init();
    } //获得数据库连接池管理器对象。无则创建返回。
    public static synchronized DBConnectionPoolManager getInstance() {
    if (instance == null) {
    instance = new DBConnectionPoolManager();
    }

    return instance;
    }

    //获得数据库连接池管理器对象。无则创建返回。
    public static synchronized DBConnectionPoolManager getInstance(String configfilePath) {
    if (instance == null) {
    if (configfilePath !=null && configfilePath.trim().length()>0)
    instance = new DBConnectionPoolManager(configfilePath);
    else  instance = new DBConnectionPoolManager();
    }

    return instance;
    } //初始化方法。加载数据库连接配置文件信息,创建数据库连接池。
    public void init() {
    File pf = new File(this.configfilePath,"SQLServerConfig.properties");
    this.configfilePath=pf.getAbsolutePath();
    FileInputStream fis = null;
    Properties p = new Properties();
    DBConnectionPool dbp = null;
    String dbpName;
    try {
    if (pf.exists()) {
    fis = new FileInputStream(pf);
    p.load(fis);
    fis.close();
    }else {
    pf.createNewFile();
    }
    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } if (p != null) {

    dbpName = p.getProperty("dbtype");
    dbp = new DBConnectionPool(dbpName, p); ht.put(dbpName, dbp);
    }

    } //获得一个数据库连接
    public Connection getConnection() {
    Connection newConn = null;
    if (ht.get("sql2k") != null) {
    newConn = ht.get("sql2k").getConnection();
    if (newConn == null) {
    newConn = ht.get("sql2k").geReConnection();
    }
    } return newConn;
    } //回收一个数据库连接
    public void callbackConnection(Connection usedConn) {
    if (usedConn != null) {
    ht.get("sql2k").callbackConnection(usedConn);
    }
    } //释放多个数据库连接池的全部连接
    public void releaseAll() {
    Enumeration<String> en = ht.keys();
    while (en.hasMoreElements()) {
    ht.get(en.nextElement().toString()).release();
    }
    } //获得多个数据库连接池的全部连接总数
    public Integer getConnectionNum() {
    Integer num = 0;
    Enumeration<String> en = ht.keys();
    while (en.hasMoreElements()) {
    num = num + ht.get(en.nextElement().toString()).ConnectionNum();
    } return num;
    } public String getConfigfilePath() {
    return configfilePath;
    } public void setConfigfilePath(String configfilePath) {
    this.configfilePath = configfilePath;
    }
    }-------------------------调用时-----------------------------
    DBConnectionPoolManager.getInstance().setConfigfilePath("abc")
    在MyEclipse中报:the method setConfigfilePath() is undefined for  the type DBConnectionPoolManager