/**
* Tries to establish a DB connection, reporting the status of this operation.
*/
public void testDataSourceAction() {
DBConnectionInfo currentDataSource = getConnectionInfo();
if (currentDataSource == null) {
return;
}
if (currentDataSource.getJdbcDriver() == null) {
JOptionPane.showMessageDialog(
null,
"No JDBC Driver specified",
"Warning",
JOptionPane.WARNING_MESSAGE);
return;
}
if (currentDataSource.getUrl() == null) {
JOptionPane.showMessageDialog(
null,
"No Database URL specified",
"Warning",
JOptionPane.WARNING_MESSAGE);
return;
}
try {
Class driverClass = getApplication().getClassLoadingService().loadClass(
currentDataSource.getJdbcDriver());
Driver driver = (Driver) driverClass.newInstance();
// connect via Cayenne DriverDataSource - it addresses some driver issues...
Connection c = new DriverDataSource(
driver,
currentDataSource.getUrl(),
currentDataSource.getUserName(),
currentDataSource.getPassword()).getConnection();
try {
c.close();
}
catch (SQLException e) {
// i guess we can ignore this...