这是一个旨在模拟连接池的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);
}
}
}