public Connection getConnection(TableDetails pTableDetails) throws SAXException {
javax.naming.InitialContext ic;
try {
ic = new javax.naming.InitialContext();
} catch (NamingException e) {
throw new LocSAXException("Failed to create initial JNDI context: "
+ e.getClass().getName() + ", " + e.getMessage(),
pTableDetails.getLocator(), e);
}
javax.sql.DataSource ds;
try {
ds = (javax.sql.DataSource) ic.lookup(pTableDetails.getDatasource());
} catch (NamingException e) {
throw new LocSAXException("Failed to lookup datasource " + pTableDetails.getDatasource()
+ ": " + e.getClass().getName() + ", " + e.getMessage(),
pTableDetails.getLocator(), e);
}
try {
Connection conn = ds.getConnection(pTableDetails.getUser(), pTableDetails.getPassword());
if (conn == null) {
throw new LocSAXException("Unable to connect to " + pTableDetails.getUrl()
+ " as user " + pTableDetails.getUser()
+ ": Datasource returned a null connection",
pTableDetails.getLocator());
}
return conn;
} catch (SQLException e) {
throw new LocSAXException("Unable to connect to datasource " + pTableDetails.getUrl()
+ " as user " + pTableDetails.getUser()
+ ": SQL State = " + e.getSQLState() + ", error code = "
+ e.getErrorCode() + ", " + e.getMessage(),
pTableDetails.getLocator(), e);
}