309 */
310 public synchronized void release() {
311 Enumeration allConnections = freeConnections.elements();
312 while (allConnections.hasMoreElements()) {
313 Connection con = (Connection) allConnections.nextElement();
314 try {
315 con.close();
316 log("关闭连接池" + name+"中的一个连接");
317 }
318 catch (SQLException e) {
319 log(e, "无法关闭连接池" + name+"中的连接");
320 }
321 }
322 freeConnections.removeAllElements();
323 }
324
325 /**
326 * 创建新的连接
327 */
328 private Connection newConnection() {
329 Connection con = null;
330 try {
331 if (user == null) {
332 con = DriverManager.getConnection(URL);
333 }
334 else {
335 con = DriverManager.getConnection(URL, user, password);
336 }
337 log("连接池" + name+"创建一个新的连接");
338 }
339 catch (SQLException e) {
340 log(e, "无法创建下列URL的连接: " + URL);
341 return null;
342 }
343 return con;
344 }
345 }
346 }
上一页 [1] [2]