Example usage for javax.sql DataSource setLoginTimeout

List of usage examples for javax.sql DataSource setLoginTimeout

Introduction

In this page you can find the example usage for javax.sql DataSource setLoginTimeout.

Prototype

@Override
void setLoginTimeout(int seconds) throws SQLException;

Source Link

Usage

From source file:com.micromux.cassandra.jdbc.DataSourceTest.java

@Test
public void testConstructor() throws Exception {
    CassandraDataSource cds = new CassandraDataSource(HOST, PORT, KEYSPACE, USER, PASSWORD, VERSION,
            CONSISTENCY, TRUST_STORE, TRUST_PASS);
    assertEquals(HOST, cds.getServerName());
    assertEquals(PORT, cds.getPortNumber());
    assertEquals(KEYSPACE, cds.getDatabaseName());
    assertEquals(USER, cds.getUser());/*from   w ww  . ja va 2  s.  c om*/
    assertEquals(PASSWORD, cds.getPassword());
    assertEquals(VERSION, cds.getVersion());

    DataSource ds = new CassandraDataSource(HOST, PORT, KEYSPACE, USER, PASSWORD, VERSION, CONSISTENCY,
            TRUST_STORE, TRUST_PASS);
    assertNotNull(ds);

    // null username and password
    java.sql.Connection cnx = ds.getConnection(null, null);
    assertFalse(cnx.isClosed());
    ds.setLoginTimeout(5);
    assertEquals(5, ds.getLoginTimeout());

    // no username and password
    cnx = ds.getConnection();
    assertFalse(cnx.isClosed());
    ds.setLoginTimeout(5);
    assertEquals(VERSION, ((CassandraConnection) cnx).getConnectionProps().get(Utils.TAG_CQL_VERSION));
    assertEquals(5, ds.getLoginTimeout());
}

From source file:org.latticesoft.util.resource.DatabaseUtil.java

/**
 * Gets a database connection from a ODBC setting
 * @param odbcName the name which the ODBC is declared.
 * @param user the user name (can be null)
 * @param password the password (can be null)
 * @param timeout the time out// w  w w  .  j a  va  2  s. c o m
 * @return the connection if successful. If not null will be returned. 
 **/
public static Connection getConnectionFromODBC(String databaseName, String user, String password, int timeout)
        throws SQLException {
    sun.jdbc.odbc.ee.DataSource ds = new sun.jdbc.odbc.ee.DataSource();
    ds.setDatabaseName(databaseName);
    if (timeout >= 0) {
        ds.setLoginTimeout(timeout);
    }
    if (user != null) {
        ds.setUser(user);
    }
    if (password != null) {
        ds.setPassword(password);
    }
    Connection conn = ds.getConnection();
    return conn;
}