Please show us the error message(s)...
请尽量使用准确的文字描述作为标题
Your next post without a proper Subject will be removed.
Original subject : 请高手帮忙看看错误在哪啊
我看了很多天了编译了很多次 仍然没发改正,请哪个高手帮忙看看 谢谢了。。。。!!!!
package connection;
import java.io.Serializable;
import java.sql.*;
import java.util.*;
public class ConnPool implements java.io.Serializable{
private String driver=null;
private String url=null;
private int size=0;
private String username="";
private String password="";
private DbConn dc=null;
private Vector pool=null;
public ConnPool(){}
public void setDriver(String driver){
if (driver!=null) this.driver=driver;
}
public String getDriver(){
return driver;
}
public void setURL(String url){
if (url!=null) this.url=url;
}
public String getURL(){
return url;
}
//设置连接条数
public void setSize(int size){
if (size>1) this.size=size;
}
public void getSize(){
return size;
}
public void setUsername(String username){
if (username!=null) this.userneme=username;
}
public String getUserName(){
return username;
}
public void setPassword(String password){
if (password!=null) this.password=password;
}
public String getPassword(){
return password;
}
public void setConnBean(DbConn dc){
if (dc!=null) this.dc=dc;
}
public DbConn getConnBean() throws Exception{
Connection conn=getConnection();
DbConn dc=new DbConn(conn);
dc.setInuse(true);
return dc;
}
//创建连接
private Connection createConnection() throws Exception{
Connection con=null;
con=DriverManager.getConnection(url,username,password);
return con;
}
public synchronized void initializePool() throws Exception{
if (driver==null)
throw new Exception("No Driver Provided!");
if (url==null)
throw new Exception("No URL Proviced!");
if (size<1)
throw new Exception("Connection Pool Size is less than 1!");
try{
Class.forName(driver);
for (int i=0; i<size; i++){
Connection con=createConnection();
if (con!=null){
DbConn dc=new DbConn(con);
addConnection(dc);
}
}
}catch (Exception e){
System.err.println(e.getMessage());
throw new Exception(e.getMessage());
}
}
private void addConnection(DbConn conn){
if (pool==null) pool=new Vector(size);
pool.addElement(conn);
}
public synchronized void releaseConnection(Connection con){
for (int i=0; i<pool.size(); i++){
Dbconn connBean=(DbConn)pool.elementAt(i);
if (connBean.getConnection()==con){
connBean.setInuse(false);
break;
}
}
}
public synchronized Connection getConnection() throws Exception{
DbConn dc = null;
for (int i=0;i<pool.size();i++){
dc=(DbConn)pool.elementAt(i);
if (dc.getInuse()==false){
dc.setInuse(true);
Connection con=dc.getConnection();
return con;
}
}
try{
Connection con=createConnection();
dc=new DbConn(con);
dc.setInuse(true);
pool.addElement(dc);
}catch (Exception e){
System.err.println(e.getMessage());
throw new Exception(e.getMessage());
}
return dc.getConnection();
}
public synchronized void emptyPool(){
for (int i=0;i<pool.size();i++){
DbConn connBean=(DbConn)pool.elementAt(i);
if (dc.getInuse()==false)
dc.close();
else{
try{
java.lang.Thread.sleep(20000);
dc.close();
}catch (InterruptedException ie){
System.err.println(ie.getMessage());
}
}
}
}
}