=========================================================================
这是DBConnectionManager.java文件package myshop;import java.io.*;
import java.sql.*;
import java.util.*;public class DBConnectionManager
{
class DBConnectionPool
{private int checkedOut;
private Vector freeConnections;
private int maxConn;
private String name;
private String password;
private String URL;
private String user;public synchronized void freeConnection(Connection connection)
{
freeConnections.addElement(connection);
checkedOut--;
notifyAll();
}public synchronized Connection getConnection()
{
Connection connection = null;
if(freeConnections.size() > 0)
{
connection = (Connection)freeConnections.firstElement();
freeConnections.removeElementAt(0);
try
{
if(connection.isClosed())
{
log("从连接池" + name + "删除一个无效连接");
connection = getConnection();
}
}
catch(SQLException _ex)
{
log("从连接池" + name + "删除一个无效连接");
connection = getConnection();
}
} else
if(maxConn == 0 || checkedOut < maxConn)
connection = newConnection();
if(connection != null)
checkedOut++;
return connection;
}public synchronized Connection getConnection(long l)
{
long l1 = (new Date()).getTime();
Connection connection;
while((connection = getConnection()) == null) 
{
try
{
wait(l);
}
catch(InterruptedException _ex) { }
if((new Date()).getTime() - l1 >= l)
return null;
}
return connection;
}private Connection newConnection()
{
Connection connection = null;
try
{
if(user == null)
connection = DriverManager.getConnection(URL);
else
connection = DriverManager.getConnection(URL, user, password);
log("连接池" + name + "创建一个新的连接");
}
catch(SQLException sqlexception)
{
log(sqlexception, "无法创建下列URL的连接: " + URL);
return null;
}
return connection;
}public synchronized void release()
{
for(Enumeration enumeration = freeConnections.elements(); enumeration.hasMoreElements();)
{
Connection connection = (Connection)enumeration.nextElement();
try
{
connection.close();
log("关闭连接池" + name + "中的一个连接");
}
catch(SQLException sqlexception)
{
log(sqlexception, "无法关闭连接池" + name + "中的连接");
}
}freeConnections.removeAllElements();
}public DBConnectionPool(String s, String s1, String s2, String s3, int i)
{
freeConnections = new Vector();
name = s;
URL = s1;
user = s2;
password = s3;
maxConn = i;
}
}
private static DBConnectionManager instance;
private static int clients;
private Vector drivers;
private PrintWriter log;
private Hashtable pools;private DBConnectionManager()
{
drivers = new Vector();
pools = new Hashtable();
init();
}private void createPools(Properties properties)
{
for(Enumeration enumeration = properties.propertyNames(); enumeration.hasMoreElements();)
{
String s = (String)enumeration.nextElement();
if(s.endsWith(".url"))
{
String s1 = s.substring(0, s.lastIndexOf("."));
String s2 = properties.getProperty(s1 + ".url");
if(s2 == null)
{
log("没有为连接池" + s1 + "指定URL");
} else
{
String s3 = properties.getProperty(s1 + ".user");
String s4 = properties.getProperty(s1 + ".password");
String s5 = properties.getProperty(s1 + ".maxconn", "0");
int i;
try
{
i = Integer.valueOf(s5).intValue();
}
catch(NumberFormatException _ex)
{
log("错误的最大连接数限制: " + s5 + " .连接池: " + s1);
i = 0;
}
DBConnectionPool dbconnectionpool = new DBConnectionPool(s1, s2, s3, s4, i);
pools.put(s1, dbconnectionpool);
log("成功创建连接池" + s1);
}
}
}}public void freeConnection(String s, Connection connection)
{
DBConnectionPool dbconnectionpool = (DBConnectionPool)pools.get(s);
if(dbconnectionpool != null)
dbconnectionpool.freeConnection(connection);
}public Connection getConnection(String s)
{
DBConnectionPool dbconnectionpool = (DBConnectionPool)pools.get(s);
if(dbconnectionpool != null)
return dbconnectionpool.getConnection();
else
return null;
}public Connection getConnection(String s, long l)
{
DBConnectionPool dbconnectionpool = (DBConnectionPool)pools.get(s);
if(dbconnectionpool != null)
return dbconnectionpool.getConnection(l);
else
return null;
}public static synchronized DBConnectionManager getInstance()
{
if(instance == null)
instance = new DBConnectionManager();
clients++;
return instance;
}private void init()
{
java.io.InputStream inputstream = getClass().getResourceAsStream("db.properties");
Properties properties = new Properties();
try
{
properties.load(inputstream);
}
catch(Exception _ex)
{
System.err.println("不能读取属性文件. 请确保db.properties在CLASSPATH指定的路径中");
return;
}
String s = properties.getProperty("logfile", "DBConnectionManager.log");
try
{
log = new PrintWriter(new FileWriter(s, true), true);
}
catch(IOException _ex)
{
System.err.println("无法打开日志文件: " + s);
log = new PrintWriter(System.err);
}
loadDrivers(properties);
createPools(properties);
}private void loadDrivers(Properties properties)
{
String s = properties.getProperty("drivers");
for(StringTokenizer stringtokenizer = new StringTokenizer(s); stringtokenizer.hasMoreElements();)
{
String s1 = stringtokenizer.nextToken().trim();
try
{
Driver driver = (Driver)Class.forName(s1).newInstance();
DriverManager.registerDriver(driver);
drivers.addElement(driver);
log("成功注册JDBC驱动程序" + s1);
}
catch(Exception exception)
{
log("无法注册JDBC驱动程序: " + s1 + ", 错误: " + exception);
}
}}private void log(String s)
{
log.println(String.valueOf(new Date()) + ": " + s);
}private void log(Throwable throwable, String s)
{
log.println(String.valueOf(new Date()) + ": " + s);
throwable.printStackTrace(log);
}public synchronized void release()
{
if(--clients != 0)
return;
DBConnectionPool dbconnectionpool;
for(Enumeration enumeration = pools.elements(); enumeration.hasMoreElements(); dbconnectionpool.release())
dbconnectionpool = (DBConnectionPool)enumeration.nextElement();for(Enumeration enumeration1 = drivers.elements(); enumeration1.hasMoreElements();)
{
Driver driver = (Driver)enumeration1.nextElement();
try
{
DriverManager.deregisterDriver(driver);
log("撤销JDBC驱动程序 " + driver.getClass().getName() + "的注册");
}
catch(SQLException sqlexception)
{
log(sqlexception, "无法撤销下列JDBC驱动程序的注册: " + driver.getClass().getName());
}
}}
}

解决方案 »

  1.   

    ==========================================================================
    这是DBconn.java文件。就是它的错老是提示
    DBconn.java:17: cannot resolve symbol
    symbol : class DBConnectionManager
    location: class myshop.DBconn
    private DBConnectionManager dcm;
    ^
    DBconn.java:77: cannot resolve symbol
    symbol : variable DBConnectionManager
    location: class myshop.DBconn
    dcm = DBConnectionManager.getInstance();
    ^
    2 errors
    源文件如下:
    package myshop;import java.io.PrintStream;
    import java.sql.*;// Referenced classes of package myshop:
    // DBConnectionManagerpublic class DBconn
    {private DBConnectionManager dcm;
    Connection conn;
    ResultSet rs;public DBconn()
    throws Exception
    {
    dcm = null;
    conn = null;
    rs = null;
    init();
    }public void CloseConn()
    throws Exception
    {
    if(rs != null)
    rs.close();
    }public void CloseConn(int i)
    throws Exception
    {
    if(rs != null)
    rs.close();
    }public ResultSet ExeQuery(String s)
    {
    try
    {
    Statement statement = conn.createStatement(1005, 1008);
    rs = statement.executeQuery(s);
    statement.close();
    dcm.freeConnection("mysql", conn);
    }
    catch(SQLException sqlexception)
    {
    System.err.println("aq.executeQuery:" + sqlexception.getMessage());
    }
    return rs;
    }public void ExeUpdate(String s)
    {
    try
    {
    Statement statement = conn.createStatement();
    statement.executeUpdate(s);
    statement.close();
    dcm.freeConnection("mysql", conn);
    }
    catch(SQLException sqlexception)
    {
    System.err.println("aq.executeUpdate:" + sqlexception.getMessage());
    }
    }private void init()
    {
    dcm = DBConnectionManager.getInstance();
    conn = dcm.getConnection("mysql");
    }
    }==========================================================================
      

  2.   

    这个错怎么解决有那个知道呢
    这是DBconn.java文件。就是它的错老是提示
    DBconn.java:17: cannot resolve symbol
    symbol : class DBConnectionManager
    location: class myshop.DBconn
    private DBConnectionManager dcm;
    ^
    DBconn.java:77: cannot resolve symbol
    symbol : variable DBConnectionManager
    location: class myshop.DBconn
    dcm = DBConnectionManager.getInstance();
    ^
    2 errors
      

  3.   

    这个错怎么解决有那个知道呢
    这是DBconn.java文件。就是它的错老是提示
    DBconn.java:17: cannot resolve symbol
    symbol : class DBConnectionManager
    location: class myshop.DBconn
    private DBConnectionManager dcm;
    ^
    DBconn.java:77: cannot resolve symbol
    symbol : variable DBConnectionManager
    location: class myshop.DBconn
    dcm = DBConnectionManager.getInstance();
    ^
    2 errors