我创建了一个包名 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&gt; set path = d:\ java \ jdk1.5 \ bin
D:\ java \ mybundle&gt; 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>
我正在努力弄清楚出了什么问题,但是徒劳无功。请帮帮我。谢谢
答案 0 :(得分:0)
您使用的是Vector
(ew),它是通用化的,但未提供类型。
如果您坚持使用Vector<Connection>
,则可能需要Vector
。
http://docs.oracle.com/javase/6/docs/api/java/util/Vector.html
那说,为什么要编写自己的连接池?