本文整理汇总了Java中java.sql.Connection.isValid方法的典型用法代码示例。如果您正苦于以下问题:Java Connection.isValid方法的具体用法?Java Connection.isValid怎么用?Java Connection.isValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.sql.Connection
的用法示例。
在下文中一共展示了Connection.isValid方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleDLLException
import java.sql.Connection; //导入方法依赖的package包/类
/**
* If DDL exception was caused by a closed connection, log info and display
* a simple error dialog. Otherwise let users report the exception.
*/
private void handleDLLException(DatabaseConnection dbConn,
DDLException e) throws SQLException, MissingResourceException {
Connection conn = dbConn == null ? null : dbConn.getJDBCConnection();
if (conn != null && !conn.isValid(1000)) {
LOGGER.log(Level.INFO, e.getMessage(), e);
NotifyDescriptor nd = new NotifyDescriptor.Message(
NbBundle.getMessage(
MakeDefaultCatalogAction.class,
"ERR_ConnectionToServerClosed"), //NOI18N
NotifyDescriptor.ERROR_MESSAGE);
DialogDisplayer.getDefault().notifyLater(nd);
} else {
Exceptions.printStackTrace(e);
}
}
示例2: getConnection
import java.sql.Connection; //导入方法依赖的package包/类
public synchronized Connection getConnection() {
Connection result = cachedConnection;
if (result != null) {
try {
if (!result.isValid(2)) {
logger.log(Level.WARNING, "closing invalid connection");
result = null;
}
}
catch (Exception e) {
logger.log(Level.WARNING, "connection became invalid: "+e.toString(), e);
result = null;
}
}
if (result == null) {
result = getNewConnection();
cachedConnection = result;
}
return result;
}
示例3: testBug56122
import java.sql.Connection; //导入方法依赖的package包/类
/**
* Tests fix for Bug#56122 - JDBC4 functionality failure when using replication connections.
*/
public void testBug56122() throws Exception {
for (final Connection testConn : new Connection[] { this.conn, getFailoverConnection(), getLoadBalancedConnection(),
getMasterSlaveReplicationConnection() }) {
testConn.createClob();
testConn.createBlob();
testConn.createNClob();
testConn.createSQLXML();
testConn.isValid(12345);
testConn.setClientInfo(new Properties());
testConn.setClientInfo("NAME", "VALUE");
testConn.getClientInfo();
testConn.getClientInfo("CLIENT");
assertThrows(SQLFeatureNotSupportedException.class, new Callable<Void>() {
public Void call() throws Exception {
testConn.createArrayOf("A_TYPE", null);
return null;
}
});
assertThrows(SQLFeatureNotSupportedException.class, new Callable<Void>() {
public Void call() throws Exception {
testConn.createStruct("A_TYPE", null);
return null;
}
});
}
}
示例4: isClose
import java.sql.Connection; //导入方法依赖的package包/类
public static boolean isClose(Connection connection){
try {
connection.isValid(1000);
return connection == null||connection.isClosed();
} catch (SQLException e) {
return false;
}
}
示例5: isValid
import java.sql.Connection; //导入方法依赖的package包/类
public static boolean isValid(Connection connection){
try {
return connection == null||connection.isValid(3);
} catch (SQLException e) {
return false;
}
}
示例6: validateConnection
import java.sql.Connection; //导入方法依赖的package包/类
private boolean validateConnection(Connection conn) {
try {
return conn.isValid(2000);
} catch (Exception e) {
log.error(String.format("��֤���ݿ�����״̬ʱ��������%s", e.getMessage()));
e.printStackTrace();
return false;
}
}
示例7: validateConnection
import java.sql.Connection; //导入方法依赖的package包/类
/**
* Verify the provided connection is valid.
*/
protected boolean validateConnection(Connection connection)
throws SQLException {
return connection != null && !connection.isClosed()
&& connection.isValid(DEFAULT_RETRY_WAIT_INTERVAL);
}