List of usage examples for org.apache.commons.dbcp DbcpException getCause
public Throwable getCause()
From source file:org.methodize.nntprss.feed.db.JdbcChannelDAO.java
public void initialize(Document config) throws Exception { Connection conn = null;/*from w w w . java2 s . co m*/ Statement stmt = null; ResultSet rs = null; boolean createTables = false; initializeDatabasePool(config); try { conn = DriverManager.getConnection(JdbcChannelDAO.POOL_CONNECT_STRING); stmt = conn.createStatement(); try { rs = stmt.executeQuery("SELECT * FROM " + TABLE_CONFIG); if (rs != null) { if (rs.next()) { int dbVersion = rs.getInt("dbVersion"); if (dbVersion < DBVERSION) { upgradeDatabase(dbVersion); } } } } catch (SQLException e) { if (e.getErrorCode() == -org.hsqldb.Trace.COLUMN_NOT_FOUND) { // Pre-version db, upgrade database upgradeDatabase(0); } else { // Our tables don't exist, so let's create them... createTables = true; } } } catch (SQLException se) { throw new RuntimeException("Problem initializing application database " + se); } catch (DbcpException de) { if (de.getCause() != null && de.getCause() instanceof SQLException) { SQLException se = (SQLException) de.getCause(); // McKoi DB if (se.getMessage().startsWith("Can not find a database to start.")) { createTables = true; } } } finally { try { if (rs != null) rs.close(); } catch (Exception e) { } try { if (stmt != null) stmt.close(); } catch (Exception e) { } try { if (conn != null) conn.close(); } catch (Exception e) { } } if (createTables) { createTables(); populateInitialChannels(config); } }