public interface PooledConnection
PooledConnection
对象表示到数据源的物理连接。该连接可以回收,而不是被关闭时,一个应用程序完成,从而减少了连接的数量,需要作出。
一个应用程序不直接使用PooledConnection
界面;相反,它是由中间层基础设施管理连接池的应用。
当应用程序调用的方法DataSource.getConnection
,它返回一个Connection
对象。如果连接池是怎么做的,那Connection
对象实际上是一个PooledConnection
对象的句柄,它是一个物理连接。
连接池管理器,通常应用程序服务器维护一个游泳池,PooledConnection
对象。如果池中有一个PooledConnection
对象可用,连接池管理器返回一个对象,是一个Connection
物理连接句柄。如果没有PooledConnection
对象可用,连接池管理器调用ConnectionPoolDataSource
方法getPoolConnection
创建新的物理连接。JDBC驱动程序实现ConnectionPoolDataSource
创建一个新的PooledConnection
对象并返回一个句柄它。
当应用程序关闭连接,它调用的方法close
Connection
。当连接池时,连接池管理器通知,因为它本身已经注册为使用ConnectionPool
方法addConnectionEventListener
ConnectionEventListener
对象。连接池管理器关闭手柄的PooledConnection
对象并返回PooledConnection
对象连接池可再次使用。因此,当一个应用程序关闭它的连接时,底层的物理连接将被循环使用,而不是被关闭。
物理连接不关闭连接池管理器调用PooledConnection
方法close
。这种方法通常被称为如果一个致命的错误使得连接不可用的有一个有序的关闭服务器或。
一个连接池管理器也往往是语句池经理,保持池PreparedStatement
对象。当应用程序关闭时一个准备好的声明中,它调用的方法close
PreparedStatement
。当Statement
池时,池经理通知,因为它本身已经注册为使用ConnectionPool
方法addStatementEventListener
StatementEventListener
对象。因此,当应用程序关闭其PreparedStatement
,底层的声明是再生而不是闭合。
Modifier and Type | Method and Description |
---|---|
void |
addConnectionEventListener(ConnectionEventListener listener)
注册了事件监听器,它会将这
PooledConnection 对象当一个事件发生时。
|
void |
addStatementEventListener(StatementEventListener listener)
注册这个
PooledConnection 对象
StatementEventListener 。
|
void |
close()
关闭,这
PooledConnection 对象代表的物理连接。
|
Connection |
getConnection()
创建并返回一个
Connection 对象,这个对象代表一个
PooledConnection 物理连接句柄。
|
void |
removeConnectionEventListener(ConnectionEventListener listener)
从组件将被通知在这
PooledConnection 对象当一个事件发生时,列表中删除给定的事件监听器。
|
void |
removeStatementEventListener(StatementEventListener listener)
从组件时会通知驱动程序检测到一个
PreparedStatement 已经关闭或无效的列表中移除指定的
StatementEventListener 。
|
Connection getConnection() throws SQLException
Connection
对象,这个对象代表一个
PooledConnection
物理连接句柄。连接池管理器调用此方法时,应用程序调用的方法
DataSource.getConnection
没有
PooledConnection
对象可用。看到
interface description
更多信息。
Connection
对象,是一本
PooledConnection
对象句柄
SQLException
-如果一个数据库访问错误发生
SQLFeatureNotSupportedException
如果JDBC驱动程序不支持此方法
void close() throws SQLException
PooledConnection
对象代表的物理连接。应用程序从不直接调用这个方法;它是由连接池模块调用的,或管理器调用的。
看到interface description
更多信息。
SQLException
-如果一个数据库访问错误发生
SQLFeatureNotSupportedException
如果JDBC驱动程序不支持此方法
void addConnectionEventListener(ConnectionEventListener listener)
PooledConnection
对象当一个事件发生时。
listener
-的一部分,通常连接池管理器,已实施
ConnectionEventListener
接口,要通知当连接关闭或有错误
removeConnectionEventListener(javax.sql.ConnectionEventListener)
void removeConnectionEventListener(ConnectionEventListener listener)
PooledConnection
对象当一个事件发生时,列表中删除给定的事件监听器。
listener
-的一部分,通常连接池管理器,已实施
ConnectionEventListener
接口和登记本
PooledConnection
对象作为一个听众
addConnectionEventListener(javax.sql.ConnectionEventListener)
void addStatementEventListener(StatementEventListener listener)
PooledConnection
对象
StatementEventListener
。组件,希望当由连接创建
PreparedStatement
s闭合或检测无效,可能用这种方法来与这
PooledConnection
对象登记一个
StatementEventListener
通知。
listener
-它实现了
StatementEventListener
接口,能与这个
PooledConnection
对象
注册一个组件
void removeStatementEventListener(StatementEventListener listener)
PreparedStatement
已经关闭或无效的列表中移除指定的
StatementEventListener
。
listener
-它实现了
StatementEventListener
接口以前注册这个
PooledConnection
对象
组件
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.