-  
       - All Known Subinterfaces:
-  
         XAConnection
 
 
 public interface PooledConnection提供连接池管理钩子的对象。 APooledConnection对象表示与数据源的物理连接。 连接可以在应用程序完成时被重新利用而不是关闭,从而减少了需要进行连接的次数。应用程序员不直接使用 PooledConnection接口; 相反,它被管理池连接的中间层基础结构所使用。当应用程序调用方法 DataSource.getConnection,它将返回一个Connection对象。 如果连接池正在完成,那么Connection对象实际上是一个PooledConnection对象的句柄,这是一个物理连接。连接池管理器(通常是应用程序服务器)维护一个 PooledConnection对象的池。 如果池中有一个PooledConnection对象可用,则连接池管理器将返回一个Connection对象,该对象是该物理连接的句柄。 如果没有PooledConnection对象可用,连接池管理器将调用ConnectionPoolDataSource方法getPoolConnection以创建新的物理连接。 实现ConnectionPoolDataSource的JDBC驱动程序创建一个新的PooledConnection对象并返回一个句柄。当应用程序关闭连接时,它将调用 Connection方法close。 当连接池正在完成时,连接池管理器将被通知,因为它已使用ConnectionPool方法addConnectionEventListener方法将其自身注册为ConnectionEventListener对象。 连接池管理停用句柄PooledConnection对象和返回PooledConnection对象,以便它可以再次使用连接池。 因此,当应用程序关闭其连接时,底层物理连接将被回收而不是关闭。如果连接池管理器为从 PoolConnection.getConnection的调用返回的逻辑句柄包装或提供代理,则当连接池管理器关闭或返回PooledConnection到池中时,池管理器必须执行以下操作之一,以响应应用程序调用Connection.close:-  在逻辑Connection处理上调用endRequest
-  致电close上的逻辑Connection句柄
 在连接池管理器调用 PooledConnection方法close之前,物理连接不会关闭。 通常调用此方法可以有序地关闭服务器,或者如果致命错误使连接无法使用。连接池管理器通常也是一个语句池管理器,维护一个 PreparedStatement对象的池。 当应用程序关闭准备好的语句时,它将调用PreparedStatement方法close。 当Statement池正在完成时,池管理器被通知,因为它已经使用ConnectionPool方法addStatementEventListener方法将其自身注册为StatementEventListener对象。 因此,当一个应用程序关闭其PreparedStatement,底层准备好的语句是循环使用而不是被关闭的。- 从以下版本开始:
- 1.4
 
-  
        
       -  
             方法摘要所有方法 接口方法 抽象方法 Modifier and Type 方法 描述 voidaddConnectionEventListener(ConnectionEventListener listener)注册给定的事件侦听器,以便在PooledConnection对象发生事件时通知它。voidaddStatementEventListener(StatementEventListener listener)注册一个StatementEventListener与此PooledConnection对象。voidclose()关闭此PooledConnection对象所代表的物理连接。ConnectiongetConnection()创建并返回一个Connection对象,该对象是PooledConnection对象表示的物理连接的句柄。voidremoveConnectionEventListener(ConnectionEventListener listener)从在PooledConnection对象发生事件时将被通知的组件列表中删除给定的事件侦听器。voidremoveStatementEventListener(StatementEventListener listener)从驱动程序检测到某个PreparedStatement已关闭或无效时将被通知的组件列表中删除指定的StatementEventListener。
 
-  
             
-  
        
       -  
             方法详细信息-  getConnectionConnection getConnection() throws SQLException 创建并返回一个Connection对象,该对象是PooledConnection对象表示的物理连接的句柄。 当应用程序调用方法DataSource.getConnection并且没有PooledConnection对象可用时,连接池管理器调用此方法。 有关详细信息,请参阅interface description。- 结果
- 
               一个 
              Connection对象的句柄这个PooledConnection对象
- 异常
-  
              SQLException- 如果发生数据库访问错误
-  
              SQLFeatureNotSupportedException- 如果JDBC驱动程序不支持此方法
- 从以下版本开始:
- 1.4
 
 -  closevoid close() throws SQLException- 异常
-  
              SQLException- 如果发生数据库访问错误
-  
              SQLFeatureNotSupportedException- 如果JDBC驱动程序不支持此方法
- 从以下版本开始:
- 1.4
 
 -  addConnectionEventListenervoid addConnectionEventListener(ConnectionEventListener listener) 注册给定的事件侦听器,以便在此PooledConnection对象发生事件时通知它。- 参数
-  
              listener- 一个组件,通常是连接池管理器,已实现了ConnectionEventListener接口,并希望在连接关闭或有错误时通知
- 另请参见:
-  
              removeConnectionEventListener(javax.sql.ConnectionEventListener)
 
 -  removeConnectionEventListenervoid removeConnectionEventListener(ConnectionEventListener listener) 从在PooledConnection对象发生事件时将被通知的组件列表中删除给定的事件侦听器。- 参数
-  
              listener- 一个组件,通常是连接池管理器,已实现了ConnectionEventListener接口,并已将此PooledConnection对象注册为侦听器
- 另请参见:
-  
              addConnectionEventListener(javax.sql.ConnectionEventListener)
 
 -  addStatementEventListenervoid addStatementEventListener(StatementEventListener listener) 注册StatementEventListener与此PooledConnection对象。 当要被通知希望组分PreparedStatement由连接创建s的关闭或被检测为无效可使用此方法来注册StatementEventListener与此PooledConnection对象。- 参数
-  
              listener- 一个组件,它实现要在PooledConnection对象中注册的StatementEventListener接口
- 从以下版本开始:
- 1.6
 
 -  removeStatementEventListenervoid removeStatementEventListener(StatementEventListener listener) 从驱动程序检测到某个PreparedStatement已关闭或无效时将通知的组件列表中删除指定的StatementEventListener。- 参数
-  
              listener- 实现StatementEventListener接口的组件,该接口先前已注册到此PooledConnection对象
- 从以下版本开始:
- 1.6
 
 
-  
 
-