When I set the login timeout on the data source, what does it do? Does it call DriverManager.setLoginTimeout() under the hood? Asking this because I’m curious as to whether it’s genuinely possible to set a per-data source login time out. Say if I have different DBMSs that I want to connect to, and these DBs have different responsiveness, so it’s reasonable to expect a different allowance for connection timeout, right?
If the answer is yes, then is there a good reason the DriverManager.setLoginTimeot() method is static?
This property should be per
DataSource(although as far as I can see there is no explicit mention of this in the JDBC spec). The DataSource implementation of some drivers don’t even use DriverManager when creating connections.Be aware though that the value set on the DriverManager will need to be explicitly used by the driver, as DriverManager itself does nothing with the value (except store it). For example the PostgreSQL driver only uses the DriverManager value if no explicit timeout was configured in the JDBC url, Properties object or DataSource properties.
The reason for
DriverManager.setLoginTimeout()is that you do not control which Driver is actually being used by the DriverManager(*) so the only way to control it is through the DriverManager.(*) except of course by the drivers you added to the classpath (and in Java 5 or earlier: which you explicitly loaded).