JAVA类型C的方法GetConnection()没有定义

时间:2022-10-25 20:58:56

this is a java program designed to simulate a connection pool but the compiler says the method GetConnection() is undefined for the type C how to deal with it ... I'm new in Java.. do you have other advice for my connection pool? Or what else implementation can I add?

这是一个用于模拟连接池的java程序,但是编译器说方法GetConnection()是不为C类型定义的,如何处理它……我新的Java . .你对我的连接池还有其他建议吗?或者我还能添加什么实现?

package hello;

public class C {

public  static void  main(String[] args) {
 CConnection con=new CConnection();
 con=GetConnection();
 System.out.println(con.pos);
 }

 public static class CConnectionManager {
  private static final int MaxConSize=10;
  private CConnection[] connections ;
  {
  connections=new CConnection[MaxConSize];
  }


  public CConnection GetConnection(){
   for(int i=0;i<connections.length;i++){
    if(1==connections[i].status){
     continue;
    }
    else if(0==connections[i].status){
   connections[i].status=1;
   connections[i].pos=i;
   return connections[i];
   }
  }

  System.out.println("No connection available,Please wait");
   return null;
 }


  public void CloseConnection (CConnection con){

  if(-1==con.pos||0==con.pos){
      System.out.println("No such connection");
  }
  else
      connections[con.pos].status=0;
  }
}



 public static class CConnection  {
  private int status=0;
  public int pos=-1;
  public void execute(String sql){

  System.out.println(sql);
  }

}

}

1 个解决方案

#1


2  

GetConnection() is an instance method of your inner CConnectionManager class.
You can only call it on an instance of that class.

GetConnection()是您的内部CConnectionManager类的实例方法。只能在该类的实例上调用它。

#1


2  

GetConnection() is an instance method of your inner CConnectionManager class.
You can only call it on an instance of that class.

GetConnection()是您的内部CConnectionManager类的实例方法。只能在该类的实例上调用它。