0

我做了一个包名mybundle。在这里面,我有一个名为DBConnectionManager.java的 java 文件。我正在尝试编译此文件,但它给出了错误消息。

DBConnectionManager.java

package mybundle;

import java.sql.*;
import java.util.*;

public class DBConnectionManager{

private String qry, driver, db, msg;

private Vector connectionPool; 

public DBConnectionManager(){

    this.connectionPool = new Vector();

    driver = "sun.jdbc.odbc.JdbcOdbcDriver";
    db = "jdbc:odbc:db";
    initialize();
}
private void initialize(){
    initializeConnectionPool();
}
private String initializeConnectionPool(){
    while(!checkIfConnectionPoolIsFull()){
        connectionPool.addElement(createNewConnectionForPool());
    }
    msg = "Connection Pool is full..";
    return msg;
}
private boolean checkIfConnectionPoolIsFull(){
    final int MAX_POOL_SIZE = 5;

    if(connectionPool.size() < 5){
        return false;
    }
    return true;
} 
private Connection createNewConnectionForPool(){
    Connection connection = null;
    try{
        Class.forName(driver);
        connection = DriverManager.getConnection(db);
    }catch(Exception ex){}
    return connection;
}
public Connection getConnectionFromPool(){
    Connection connection = null;
    if(connectionPool.size() > 0){
        connection = (Connection)connectionPool.firstElement();
        connectionPool.removeElementAt(0); 
    }
    return connection;
}
public void returnConnectionToPool(Connection connection){
    connectionPool.addElement(connection);

}}

这是我放置 Tomcat、JDK1.5 和我的包 mybndle 的地方

我的jdk1.5和tomcat在:

D:\java\jdk1.5

D:\java\tomcat

D:\java\mybundle

这就是我编译 DBConnectionManager.java 文件的方式

D:\java\mybundle>设置路径=d:\java\jdk1.5\bin

D:\java\mybundle>javac DBConnectionManager.java

我收到此错误消息

D:\>cd java

D:\Java>cd mybundle

D:\Java\mybundle>set path=d:\java\jdk1.5\bin

D:\Java\mybundle>javac DBConnectionManager.java

Note: DBConnectionManager.java uses unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

D:\Java\mybundle>

我太努力找出问题所在,但徒劳无功。请帮帮我。谢谢

4

1 回答 1

0

您正在使用Vector(ew),它是泛型的,但不提供类型。

如果您Vector<Connection>坚持使用Vector.

http://docs.oracle.com/javase/6/docs/api/java/util/Vector.html

也就是说,为什么要编写自己的连接池?

于 2012-11-24T18:27:40.207 回答