} catch (ClassNotFoundException ex) {
String errorMsg =
"ERROR: cannot load JDBC driver class [" + getJdbcDriverClass()+ "]. "
+"Likely problem: JDBC driver jar missing from server classpath.";
errorMessage(errorMsg);
throw new StartupException(errorMsg, ex, startupLog);
}
successMessage("SUCCESS: loaded JDBC driver class [" +getJdbcDriverClass()+ "]");
if (getJdbcUsername() != null || getJdbcPassword() != null) {
props = new Properties();
if (getJdbcUsername() != null) props.put("user", getJdbcUsername());
if (getJdbcPassword() != null) props.put("password", getJdbcPassword());
}
// Else attempt to locate JNDI datasource
} else {
String name = (getJndiName().indexOf(":") == -1 ? "java:comp/env/" + getJndiName() : getJndiName());
successMessage("-- Using JNDI datasource name: " + name);
try {
InitialContext ic = new InitialContext();
dataSource = (DataSource)ic.lookup(name);
} catch (NamingException ex) {
String errorMsg =
"ERROR: cannot locate JNDI DataSource [" +name+ "]. "
+"Likely problem: no DataSource or datasource is misconfigured.";
errorMessage(errorMsg);
throw new StartupException(errorMsg, ex, startupLog);
}
successMessage("SUCCESS: located JNDI DataSource [" +name+ "]");
}
// So far so good. Now, can we get a connection?
try {
Connection testcon = getConnection();
testcon.close();
} catch (Throwable t) {
String errorMsg =
"ERROR: unable to obtain database connection. "
+"Likely problem: bad connection parameters or database unavailable.";
errorMessage(errorMsg);
throw new StartupException(errorMsg, t, startupLog);
}
}