@Override
    public void afterPropertiesSet() throws Exception {
        Connection conn = null;

        try {
            boolean createTables = true;

            try {
                conn = dataSource.getConnection();

                ResultSet rs = conn.getMetaData().getTables(conn.getCatalog(), null, "EVENTS_CUSTOMINFO", null);
                while (rs.next()) {
                    LOG.warning("Tables and indexes will not be created as they are already existing");
                    createTables = false;
                }
            } catch (SQLException e) {
                LOG.log(Level.WARNING, "Tables and indexes can not be created", e);
                createTables = false;
            }

            if (createTables) {
                ScriptRunner sr = new ScriptRunner(conn, false, false);
                sr.setLogWriter(null);
                sr.setErrorLogWriter(null);
                sr.runScript(new InputStreamReader(this.getClass().getResourceAsStream("/" + createSql)));
                if (createSqlInd != null && !createSqlInd.equals("")) {
                    sr.runScript(new InputStreamReader(this.getClass().getResourceAsStream("/" + createSqlInd)));
                } else {
                    LOG.warning("The script to create indexes has not been set. Indexes will not be created.");
                }
            }
        } finally {
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                    LOG.warning("Unable to close JDBC connection.");
                }
            }
        }
    }
@ Override public void afterPropertiesSet ( ) throws Exception { Connection conn = null ; try { boolean createTables = true ; try { conn = dataSource . getConnection ( ) ; ResultSet rs = conn . getMetaData ( ) . getTables ( conn . getCatalog ( ) , null , "EVENTS_CUSTOMINFO" , null ) ; while ( rs . next ( ) ) { LOG . warning ( "Tables and indexes will not be created as they are already existing" ) ; createTables = false ; } } catch ( SQLException e ) { LOG . log ( Level . WARNING , "Tables and indexes can not be created" , e ) ; createTables = false ; } if ( createTables ) { ScriptRunner sr = new ScriptRunner ( conn , false , false ) ; sr . setLogWriter ( null ) ; sr . setErrorLogWriter ( null ) ; sr . runScript ( new InputStreamReader ( this . getClass ( ) . getResourceAsStream ( "/" + createSql ) ) ) ; if ( createSqlInd != null && ! createSqlInd . equals ( "" ) ) { sr . runScript ( new InputStreamReader ( this . getClass ( ) . getResourceAsStream ( "/" + createSqlInd ) ) ) ; } else { LOG . warning ( "The script to create indexes has not been set. Indexes will not be created." ) ; } } } finally { if ( conn != null ) { try { conn . close ( ) ; } catch ( SQLException e ) { LOG . warning ( "Unable to close JDBC connection." ) ; } } } }
/*
(non-Javadoc)

@see
org.springframework.beans.factory.InitializingBean#afterPropertiesSet()