Java Code Examples for java.sql.DriverManager#setLoginTimeout()

The following examples show how to use java.sql.DriverManager#setLoginTimeout() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Application.java    From bigtable-sql with Apache License 2.0 6 votes vote down vote up
private void preferencesHaveChanged(PropertyChangeEvent evt)
{
	final String propName = evt != null ? evt.getPropertyName() : null;

	if (propName == null || propName.equals(SquirrelPreferences.IPropertyNames.SHOW_TOOLTIPS))
	{
		ToolTipManager.sharedInstance().setEnabled(_prefs.getShowToolTips());
	}

	if (propName == null || propName.equals(SquirrelPreferences.IPropertyNames.JDBC_DEBUG_TYPE))
	{
		setupJDBCLogging();
	}

	if (propName == null || propName.equals(SquirrelPreferences.IPropertyNames.LOGIN_TIMEOUT))
	{
		DriverManager.setLoginTimeout(_prefs.getLoginTimeout());
	}

	if (propName == null || propName == SquirrelPreferences.IPropertyNames.PROXY)
	{
		new ProxyHandler().apply(_prefs.getProxySettings());
	}
}
 
Example 2
Source File: TestFBConnectionTimeout.java    From jaybird with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Test for connect timeout specified through connection property (in the url)
 */
@Test
public void connectTimeoutFromProperty() {
    // Reset DriverManager timeout
    DriverManager.setLoginTimeout(0);
    long startTime = System.currentTimeMillis();
    try {
        DriverManager.getConnection(buildTestURL() + "?connectTimeout=1&encoding=NONE", "sysdba", "masterkey");
        fail("Expected connection to fail");
    } catch (SQLException e) {
        long endTime = System.currentTimeMillis();
        long difference = endTime - startTime;
        assertEquals("Expected error code for \"Unable to complete network request\"", 335544721, e.getErrorCode());
        assertEquals("Unexpected timeout duration (in ms)", 1000, difference, TIMEOUT_DELTA_MS);
    }
}
 
Example 3
Source File: TestFBConnectionTimeout.java    From jaybird with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Test for connect timeout specified through {@link java.sql.DriverManager#setLoginTimeout(int)}
 */
@Test
public void connectTimeoutFromDriverManager() {
    // Timeout set through DriverManager
    DriverManager.setLoginTimeout(2);
    long startTime = System.currentTimeMillis();
    try {
        DriverManager.getConnection(buildTestURL() + "?encoding=NONE", "sysdba", "masterkey");
        fail("Expected connection to fail");
    } catch (SQLException e) {
        long endTime = System.currentTimeMillis();
        long difference = endTime - startTime;
        assertEquals("Expected error code for \"Unable to complete network request\"", 335544721, e.getErrorCode());
        assertEquals("Unexpected timeout duration (in ms)", 2000, difference, TIMEOUT_DELTA_MS);
    } finally {
        // Reset to default
        DriverManager.setLoginTimeout(0);
    }
}
 
Example 4
Source File: ConnectTest.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * DERBY-2026 make sure loginTimeout does not
 * affect queries
 * @throws SQLException
 */
public void clientTestDerby2026LoginTimeout() throws SQLException  {
    String url = "jdbc:splice://" + TestConfiguration.getCurrent().getHostName() +":" +
            TestConfiguration.getCurrent().getPort() + "/" + TestConfiguration.getCurrent().getDefaultDatabaseName();
    try {
        DriverManager.setLoginTimeout(10);
        //System.out.println(url);
        try {
            Class.forName("org.apache.derby.jdbc.ClientDriver");
        } catch (ClassNotFoundException e) {
            fail(e.getMessage());
        }
        Connection conn = DriverManager.getConnection(url);
        TestRoutines.installRoutines(conn);
        CallableStatement cs = conn.prepareCall("CALL TESTROUTINE.SLEEP(20000)");
        cs.execute();
        //rollback to make sure our connection is ok.
        conn.rollback();
    } finally {
        DriverManager.setLoginTimeout(0);
    }
}
 
Example 5
Source File: TestFBConnectionTimeout.java    From jaybird with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Test if a normal connection will work when the timeout is specified in the connection properties.
 */
@Test
public void normalConnectionWithTimeoutFromProperty() throws Exception {
    // Reset DriverManager timeout
    DriverManager.setLoginTimeout(0);
    FBManager fbManager = createFBManager();
    defaultDatabaseSetUp(fbManager);
    try {
        Properties properties = FBTestProperties.getDefaultPropertiesForConnection();
        properties.setProperty("connectTimeout", "1");
        Connection connection = DriverManager.getConnection(FBTestProperties.getUrl(), properties);
        connection.close();
    } finally {
        defaultDatabaseTearDown(fbManager);
    }
}
 
Example 6
Source File: DataSourcePoolFactory.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
public DataSourcePoolFactory(){
	registeredDrivers 		= new HashSet<String>();
	longTermPoolFactory		= new LongTermPoolFactory();
	shortTermPoolFactory	= new ShortTermPoolFactory();
	
	DriverManager.setLoginTimeout(30);
}
 
Example 7
Source File: DriverManagerTests.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Validate that values set using setLoginTimeout will be returned by
 * getLoginTimeout
 */
@Test
public void test() {
    int[] vals = {-1, 0, 5};
    for (int val : vals) {
        DriverManager.setLoginTimeout(val);
        assertEquals(val, DriverManager.getLoginTimeout());
    }
}
 
Example 8
Source File: DBUtils.java    From mysql_perf_analyzer with Apache License 2.0 5 votes vote down vote up
public static String testConnection(DBInstanceInfo dbinfo, 
			String username, 
			String password)
{
  String url = dbinfo.getConnectionString();
	Connection conn = null;
	Statement stmt = null;
	ResultSet rs = null;
	try
	{
	  logger.info("Test connection to ("+dbinfo+"): "+url);
	  DriverManager.setLoginTimeout(60);
	  conn = DriverManager.getConnection(url, username, password);
	  if(conn!=null)
	  {
	    dbinfo.setConnectionVerified(true);
		logger.info("Connection test succeeded to ("+dbinfo+")");
	    return null;
    }
	else
    {
		logger.log(Level.SEVERE,"Connection test failed: reason null.");
	    return "Connection test failed: reason null.";    	  
    }
	  
	}catch(Exception ex)
	{
	    logger.log(Level.SEVERE,"Exception", ex);
        return "Connection test to "+ url+" failed: "+ex.getMessage();
	}finally
	{
		DBUtils.close(rs);
		DBUtils.close(stmt);
		DBUtils.close(conn);
	}
  }
 
Example 9
Source File: DriverManagerTests.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Validate that values set using setLoginTimeout will be returned by
 * getLoginTimeout
 */
@Test
public void test() {
    int[] vals = {-1, 0, 5};
    for (int val : vals) {
        DriverManager.setLoginTimeout(val);
        assertEquals(val, DriverManager.getLoginTimeout());
    }
}
 
Example 10
Source File: DriverManagerTests.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Validate that values set using setLoginTimeout will be returned by
 * getLoginTimeout
 */
@Test
public void test() {
    int[] vals = {-1, 0, 5};
    for (int val : vals) {
        DriverManager.setLoginTimeout(val);
        assertEquals(val, DriverManager.getLoginTimeout());
    }
}
 
Example 11
Source File: MyPerfContext.java    From mysql_perf_analyzer with Apache License 2.0 4 votes vote down vote up
/**
  * All the top level beans, sql manager, connection manage, db manager, etc, will be initialized here.
  */
 public void afterPropertiesSet() throws Exception 
 {
   configureLogging();
Logger logger = Logger.getLogger(this.getClass().getName());		
logger.info("Setup afterPropertiesSet.");

logger.info("Loading JDBC Drivers");
if(this.jdbcDriver!=null)
{
   DriverManager.setLoginTimeout(60);
   logger.info("Set JDBC DriverManager loginTimeout as 60 seconds");
   for(Map.Entry<String, String> e: jdbcDriver.entrySet())
   {
	  logger.info("Loading "+e.getKey()+": "+e.getValue());
	  try
	  {
	    Class.forName(e.getValue());	  
		logger.info("Loaded "+e.getKey()+": "+e.getValue());
	  }catch(Throwable ex)
	  {
	    logger.info("Failed to Load "+e.getKey()+": "+e.getValue());			  
	  }
   }
}

alertRootPath = new File(new File(this.fileReposirtoryPath), "alerts");
alertRootPath.mkdirs();

this.sqlManager.setSqlPath(sqlPath);
this.sqlManager.init();

this.metricsDef.init();
logger.info("Refreshing metrics list ...");
refreshMetricsList();
logger.info("Retrieved metrics list: " + this.metricsList.size());

this.metaDb.setDbkey(this.configRepKey);
this.metaDb.init();

this.dbInfoManager.setMetaDb(metaDb);//since we store db info now in metricsdb, 
        //it can only be initialized after metricsDB initialized 

this.userManager.setMetaDb(metaDb);
this.auth.setContext(this);	
this.queryEngine.setSqlManager(this.sqlManager);
this.queryEngine.setFrameworkContext(this);
   this.statDefManager.init();
   
logger.info("Initialize AutoScanner ...");
this.myperfConfig.init(this);
this.snmpSettings.init(this);
if(this.myperfConfig.isConfigured())
{
  this.initMetricsDB(); //move metrics db creation and initialization away from scanner
     this.alertSettings.setContext(this);
  if(this.metricDb != null)
  {
    this.dbInfoManager.init(this.metricDb);//need metricsDB to update
	this.metricsDef.getUdmManager().loadSubscriptions(this);
   	this.metricDb.loadAlertSetting(this.alertSettings);//load alert setting after DB info is loaded.
  }
}
   this.instanceStatesManager.init(this);
this.hipchat.init(this);

autoScanner = new AutoScanner(this);
autoScanner.init();//it will update metricsDB
if(autoScanner.isInitialized())
{
  logger.info("Starting AutoScanner ...");
  autoScanner.start();
   }

logger.info("Done setup afterPropertiesSet.");
 }
 
Example 12
Source File: SimpleDataSource.java    From doma with Apache License 2.0 4 votes vote down vote up
@Override
public void setLoginTimeout(int seconds) {
  DriverManager.setLoginTimeout(seconds);
}
 
Example 13
Source File: AbstractHiveServer.java    From incubator-sentry with Apache License 2.0 4 votes vote down vote up
public Connection createConnection(String user, String password) throws Exception{
  String url = getURL();
  DriverManager.setLoginTimeout(0);
  Connection connection =  DriverManager.getConnection(url, user, password);
  return connection;
}
 
Example 14
Source File: OperateSystemDBImpl.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected Connection getConnection(String driver, String url, Properties prop) throws ClassNotFoundException, SQLException {
	Class.forName(driver);
	DriverManager.setLoginTimeout(1);
	return DriverManager.getConnection(url, prop);
}
 
Example 15
Source File: PooledDataSource.java    From mybaties with Apache License 2.0 4 votes vote down vote up
@Override
public void setLoginTimeout(int loginTimeout) throws SQLException {
  DriverManager.setLoginTimeout(loginTimeout);
}
 
Example 16
Source File: UnpooledDataSource.java    From mybatis with Apache License 2.0 4 votes vote down vote up
@Override
public void setLoginTimeout(int loginTimeout) throws SQLException {
  DriverManager.setLoginTimeout(loginTimeout);
}
 
Example 17
Source File: UnpooledDataSource.java    From ZhihuSpider with MIT License 4 votes vote down vote up
public void setLoginTimeout(int loginTimeout) throws SQLException {
	DriverManager.setLoginTimeout(loginTimeout);
}
 
Example 18
Source File: SimpleDataSource.java    From vibur-dbcp with Apache License 2.0 4 votes vote down vote up
@Override
public void setLoginTimeout(int seconds) throws SQLException {
    DriverManager.setLoginTimeout(seconds);
}
 
Example 19
Source File: CassandraDataSource.java    From cassandra-jdbc-wrapper with Apache License 2.0 4 votes vote down vote up
public void setLoginTimeout(int timeout)
{
    DriverManager.setLoginTimeout(timeout);
}
 
Example 20
Source File: SimpleDataSource.java    From oxygen with Apache License 2.0 4 votes vote down vote up
@Override
public void setLoginTimeout(int seconds) {
  DriverManager.setLoginTimeout(seconds);
}