DBCP Connection Pool loginTimeout

后端 未结 2 595
忘了有多久
忘了有多久 2021-02-14 10:13

According to the DBCP Document, BasicDataSource does not support setLoginTimeout(). My question is then how do I set a LoginTimeout for the creation of Connection objects? I kno

相关标签:
2条回答
  • 2021-02-14 10:52

    @Sap is right, you might use the JDBC url in order to add connection properties, for example:

    basicDataSource.setUrl("jdbc:postgresql://192.168.0.100:5432/postgres?connectTimeout=TIME_IN_SECONDS");
    

    Where TIME_IN_SECONDS can be any intenger value.

    Besides, we can use BasicDataSource#setConnectionProperties. As the parameter says:

    The connection properties that will be sent to our JDBC driver when establishing new connections. Format of the string must be [propertyName=property;]* NOTE - The "user" and "password" properties will be passed explicitly, so they do not need to be included here.

    So, it might be something like (and following the previous example):

    basicDataSource.setUrl("jdbc:postgresql://192.168.0.100:5432/postgres");
    basicDataSource.setConnectionProperties("connectTimeout=TIME_IN_SECONDS");
    

    P.S:

    You can add more properties using ; at the end of the property.

    0 讨论(0)
  • 2021-02-14 10:54

    Well there is always an option to add correct parameter to the URL. Depending on which DB you are using you can add one of the parameters in JDBC url.

    Here is the link that confirms that BasicDataSource does not support loginTimeout

    And at the bottom of this blog There is a table which lists URL parameters for connection timeouts.

    0 讨论(0)
提交回复
热议问题