日期:2014-05-16 浏览次数:20534 次
String url = "jdbc:oracle:thin:@127.0.0.1:1521:xe";
String username ="system";
String password = "admin";
startTime = System.currentTimeMillis();
for(int i=0;i<100;i++){
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
}catch(ClassNotFoundException e){
e.printStackTrace();
}
Connection conn = DriverManager.getConnection(url,username,password);
Statement stmt = conn.createStatement();//创建陈述对象
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()){
//执行指定代码段
}
rs.close();
stmt.close();
conn.close();
}
System.out.println("经过100次循环调用,不使用连接池所花费的时间为"+(System.currentTimeMillis()-startTime)+"ms");Exception in thread "main" java.sql.SQLException: Listener refused the connection with the following error: ORA-12519, TNS:no appropriate service handler found The Connection descriptor used by the client was: 127.0.0.1:1521:xe at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:261) at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387) at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:414) at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165) at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35) at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801) at java.sql.DriverManager.getConnection(DriverManager.java:582) at java.sql.DriverManager.getConnection(DriverManager.java:185) at ConnectionPoolTest.main(ConnectionPoolTest.java:50)