问题描述
packagebbs;importjava.sql.*;importjava.util.*;publicclassConnPool{privateintConnNow=0;privateVectorconnections=newVector();privateStringPoolName;privateStringDriverName;privateStringDbId;privateStringUserName;privateStringPassword;privateintMaxConn;publicConnPool(StringPoolName,StringDriverName,StringDbId,StringUserName,StringPassword,intMaxConn){this.PoolName=PoolName;this.DriverName=DriverName;this.DbId=DbId;this.UserName=UserName;this.Password=Password;this.MaxConn=MaxConn;}publicsynchronizedvoidreleaseConnection(Connectionconn){connections.addElement(conn);ConnNow--;}publicsynchronizedConnectiongetConnection(){Connectionconn=null;if(connections.size()>0){conn=(Connection)connections.elementAt(0);connections.removeElementAt(0);try{if(conn.isClosed())conn=getConnection();}catch(Exceptionex){ex.printStackTrace();}}elseif(MaxConn==0||ConnNow<MaxConn){conn=newConnection();}if(conn!=null){ConnNow++;}returnconn;}privateConnectionnewConnection(){Connectionconn=null;try{Class.forName(DriverName);conn=DriverManager.getConnection(DbId,UserName,Password);}catch(Exceptione){e.printStackTrace();returnnull;}returnconn;}publicsynchronizedvoidcloseConn(){EnumerationallConnections=connections.elements();while(allConnections.hasMoreElements()){Connectionconn=(Connection)allConnections.nextElement();try{conn.close();}catch(SQLExceptione){e.printStackTrace();}}connections.removeAllElements();}}编译时提示使用了未经检查或不安全的操作.怎么解决~~
解决方案
解决方案二:
没导包,
解决方案三:
应该泛型问题吧,试试这样privateVector<?>connections=newVector<?>();
解决方案四:
java.util.Vector的方法allElement(E)添加的是普通类型,而你添加的是个conn类型Connection不为普通类型,所以会有注意:ConnPool.java使用了未经检查或不安全的操作。注意:要了解详细信息,请使用-Xlint:unchecked重新编译。这样的提示,但这样的提示不影响文件的正常编译和运行。。