Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Servlet/JSP/JSF/JavaFX Script  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
reply to postflat modethreaded modego to previous topicgo to next topicgo to back
作者 请高手帮忙看看错误在哪啊(Connection Pool)
dream830101





发贴: 4
于 2005-08-23 15:56 user profilesend a private message to usersend email to dream830101reply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
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());
}
}
}
}
}


why edited on 2005-09-05 23:08

                 朋友——让我们共同进步吧

梦梦 QQ:369232594

Java应用者与<IDE/环境>

话题树型展开
人气 标题 作者 字数 发贴时间
2273 请高手帮忙看看错误在哪啊(Connection Pool) dream830101 3837 2005-08-23 15:56
1788 Re:请高手帮忙看看错误在哪啊 chengbd 12 2005-08-23 20:46
1812 Re:请高手帮忙看看错误在哪啊 liang 3 2005-09-04 12:43
1924 Re:请高手帮忙看看错误在哪啊 YuLimin 5162 2005-09-05 16:03

reply to postflat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923