DBCP Connection Pool loginTimeout

蹲街弑〆低调 提交于 2019-12-03 12:41:30

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.

@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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!