想要实现在缓冲池中预先添加一定数量的数据库连接,其中的put方法出现问题,具体提示:The method put(Object, Object) in the type Hashtable is not applicable for the arguments (int, DBConnection)
代码部分如下:
 public void initConnection()
 {
 DBConnection addconnection=new DBConnection();
 for(int i=0;i<=maxconnection/2;i++)
 {
 addconnection.setKey(i);
 connectionpool.put(i,addconnection);
 }
 
 }
  下面是同一包中不同类的方法。 
public DBConnection(String url,String user,String pwd,String forName,int key)
{
  this.url=url;
  this.user=user;
  this.pwd=pwd;
  this.forName=forName;
  this.key=key;
  connection=getConnectionInstance();
  
 }
public DBConnection(){}
}
 public void setKey(int key)
{
  this.key=key;
 }
还是新手,希望能指点的细致些....

解决方案 »

  1.   

    The method put(Object, Object) in the type Hashtable is not applicable for the arguments (int, DBConnection)
      

  2.   

    connectionpool.put(new Integer(i),addconnection);
    你要用jdk1.5及以上,你那么写就不会有问题
      

  3.   

    connectionpool.put(new Integer(i),addconnection);
    版本问题
      

  4.   

    我觉得应该就是那个问题,你换个版本的JDK试一试吧
      

  5.   

    已经解决了,我的是MyEclipse8.0的,jdk没自己再装,把i换成new Integer(i)就可以了,谢谢大家...因为把Hashtable换成HashMap后下面的方法也得换,所以就放弃了,呵呵,个人比较菜,还是很谢谢.....