I'm trying to set a connection timeout for a project that uses Eclipse's Data Tools Platform. The purpose is to prevent waiting if a database connection takes too long to establish. The project supports several database types.
If the project used plain java.sql, I could set the timeout as follows:
final int TIMEOUT_SECONDS = 5;
DriverManager.setLoginTimeout(TIMEOUT_SECONDS);
Connection connection = DriverManager.getConnection(jdbcUrl, username, password);
I tried to look for something similar in org.eclipse.datatools.connectivity classes, such as IConnectionProfile. So far, I have been unable to locate a specific method like DriverManager.setLoginTimeout.
Both java.sql and org.eclipse.datatools.connectivity support adding properties to set connection information:
java.sql
Properties properties = new Properties();
properties.setProperty("user", connectionInfo.username);
properties.setProperty("password", connectionInfo.password);
String connectionTimeoutProperty = getConnectionTimeoutProperty(); // depends on the database vendor
String connectionTimeoutValue = getConnectionTimeoutPropertyValue(); // The value in seconds or milliseconds - also depends on the vendor
properties.setProperty(connectionTimeoutProperty, connectionTimeoutValue);
connection = DriverManager.getConnection(jdbcUrl, properties);
org.eclipse.database.connectivity
Properties properties = new Properties();
// Similar property setup as above.
ProfileManager.getInstance().createProfile(profileName, "Auto Generated", "org.eclipse.datatools.connectivity.db.generic.connectionProfile", properties, "", false);
return ProfileManager.getInstance().getProfileByName(profileName);
Using properties, I've been able to set a timeout for most of the databases. For instance, Oracle supports a property named oracle.net.CONNECT_TIMEOUT expressed in milliseconds, whereas Microsoft SQL Server suports a property named loginTimeout expressed in seconds.
I have yet to find values for Sybase, Teradata, and Netezza.
Question 1: Is there a simpler mechanism to set a login timeout for the Data Tools Platform? Question 2: If there is no better solution, is there a way to set the timeout for Sybase, Teradata, and Netezza? I can handle properties with different names and value types.