Example usage for java.sql Connection setNetworkTimeout

List of usage examples for java.sql Connection setNetworkTimeout

Introduction

In this page you can find the example usage for java.sql Connection setNetworkTimeout.

Prototype

void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException;

Source Link

Document

Sets the maximum period a Connection or objects created from the Connection will wait for the database to reply to any one request.

Usage

From source file:com.adaptris.jdbc.connection.FailoverDatasourceTest.java

@Test
public void testNetworkTimeout() throws Exception {
    Connection conn = new MyProxy();

    try {/*from  w  ww.  j  av a 2 s.co  m*/
        try {
            conn.getNetworkTimeout();
        } catch (SQLException e) {
            // Feature isn't supported by Derby
        }
        try {
            conn.setNetworkTimeout(Executors.newSingleThreadExecutor(), 1000);
        } catch (SQLException e) {
            // Feature isn't supported by Derby
        }
    } finally {
        JdbcUtil.closeQuietly(conn);
    }
}