public void setupDB() throws Exception {

        if (m_bean.isInitialized()) {
            System.out.println("Setup-Bean initialized successfully.");
            CmsSetupDb db = new CmsSetupDb(m_bean.getWebAppRfsPath());
            try {
                // try to connect as the runtime user
                db.setConnection(
                    m_bean.getDbDriver(),
                    m_bean.getDbWorkConStr(),
                    m_bean.getDbConStrParams(),
                    m_bean.getDbWorkUser(),
                    m_bean.getDbWorkPwd(),
                    false);
                if (!db.noErrors()) {
                    // try to connect as the setup user
                    db.closeConnection();
                    db.clearErrors();
                    db.setConnection(
                        m_bean.getDbDriver(),
                        m_bean.getDbCreateConStr(),
                        m_bean.getDbConStrParams(),
                        m_bean.getDbCreateUser(),
                        m_bean.getDbCreatePwd());
                }
                if (!db.noErrors() || !m_bean.validateJdbc()) {
                    throw new Exception("DB Connection test faild.");
                }
            } finally {
                db.clearErrors();
                db.closeConnection();
            }
        }

        System.out.println("DB connection tested successfully.");

        CmsSetupDb db = null;
        boolean dbExists = false;
        if (m_bean.isInitialized()) {
            if (m_props.isCreateDb() || m_props.isCreateTables()) {
                db = new CmsSetupDb(m_bean.getWebAppRfsPath());
                // check if database exists
                if (m_bean.getDatabase().startsWith("oracle")
                    || m_bean.getDatabase().startsWith("db2")
                    || m_bean.getDatabase().startsWith("as400")) {
                    db.setConnection(
                        m_bean.getDbDriver(),
                        m_bean.getDbWorkConStr(),
                        m_bean.getDbConStrParams(),
                        m_bean.getDbWorkUser(),
                        m_bean.getDbWorkPwd());
                } else {
                    db.setConnection(
                        m_bean.getDbDriver(),
                        m_bean.getDbWorkConStr(),
                        m_bean.getDbConStrParams(),
                        m_bean.getDbCreateUser(),
                        m_bean.getDbCreatePwd(),
                        false);
                    dbExists = db.noErrors();
                    if (dbExists) {
                        db.closeConnection();
                    } else {
                        db.clearErrors();
                    }
                }
                if (!dbExists || m_props.isDropDb()) {
                    db.closeConnection();
                    if (!m_bean.getDatabase().startsWith("db2") && !m_bean.getDatabase().startsWith("as400")) {
                        db.setConnection(
                            m_bean.getDbDriver(),
                            m_bean.getDbCreateConStr(),
                            m_bean.getDbConStrParams(),
                            m_bean.getDbCreateUser(),
                            m_bean.getDbCreatePwd());
                    }
                }
            }
        }
        if (!m_props.isCreateDb() && !m_props.isCreateTables() && !dbExists) {
            throw new Exception("You have not created the Alkacon OpenCms database.");
        }
        if (dbExists && m_props.isCreateTables() && !m_props.isDropDb() && (db != null)) {
            throw new Exception("You have selected to not drop existing DBs, but a DB with the given name exists.");
        }
        if (dbExists && m_props.isCreateDb() && m_props.isDropDb() && (db != null)) {
            // drop the DB
            db.closeConnection();
            db.setConnection(
                m_bean.getDbDriver(),
                m_bean.getDbWorkConStr(),
                m_bean.getDbConStrParams(),
                m_bean.getDbCreateUser(),
                m_bean.getDbCreatePwd());
            db.dropDatabase(m_bean.getDatabase(), m_bean.getReplacer());
            if (!db.noErrors()) {
                for (String error : db.getErrors()) {
                    System.err.println(error + "\n");
                    System.err.println(HR + "\n");
                }
                db.clearErrors();
                throw new Exception("Error ocurred while dropping the DB!");
            }
            System.out.println("Database dropped successfully.");
        }

        if (m_props.isCreateDb() && (db != null)) {
            // Create Database
            db.createDatabase(m_bean.getDatabase(), m_bean.getReplacer());
            if (!db.noErrors()) {
                for (String error : db.getErrors()) {
                    System.err.println(error + "\n");
                    System.err.println(HR + "\n");
                }
                db.clearErrors();
                throw new Exception("Error ocurred while creating the DB!");
            }
            db.closeConnection();
            System.out.println("Database created successfully.");
        }

        if (m_props.isCreateTables() && (db != null)) {
            db.setConnection(
                m_bean.getDbDriver(),
                m_bean.getDbWorkConStr(),
                m_bean.getDbConStrParams(),
                m_bean.getDbWorkUser(),
                m_bean.getDbWorkPwd());
            //Drop Tables (intentionally quiet)
            db.dropTables(m_bean.getDatabase());
            db.clearErrors();
            db.closeConnection();
            // reopen the connection in order to display errors
            db.setConnection(
                m_bean.getDbDriver(),
                m_bean.getDbWorkConStr(),
                m_bean.getDbConStrParams(),
                m_bean.getDbWorkUser(),
                m_bean.getDbWorkPwd());
            //Create Tables
            db.createTables(m_bean.getDatabase(), m_bean.getReplacer());
            if (!db.noErrors()) {
                for (String error : db.getErrors()) {
                    System.err.println(error + "\n");
                    System.err.println(HR + "\n");
                }
                db.clearErrors();
                throw new Exception("Error ocurred while creating tables.");
            }
            db.closeConnection();
            System.out.println("Tables created successfully.");
        }
        if (db != null) {
            db.closeConnection();
        }
        System.out.println("Database setup was successful.");
    }
public void setupDB ( ) throws Exception { if ( m_bean . isInitialized ( ) ) { System . out . println ( "Setup-Bean initialized successfully." ) ; CmsSetupDb db = new CmsSetupDb ( m_bean . getWebAppRfsPath ( ) ) ; try { db . setConnection ( m_bean . getDbDriver ( ) , m_bean . getDbWorkConStr ( ) , m_bean . getDbConStrParams ( ) , m_bean . getDbWorkUser ( ) , m_bean . getDbWorkPwd ( ) , false ) ; if ( ! db . noErrors ( ) ) { db . closeConnection ( ) ; db . clearErrors ( ) ; db . setConnection ( m_bean . getDbDriver ( ) , m_bean . getDbCreateConStr ( ) , m_bean . getDbConStrParams ( ) , m_bean . getDbCreateUser ( ) , m_bean . getDbCreatePwd ( ) ) ; } if ( ! db . noErrors ( ) || ! m_bean . validateJdbc ( ) ) { throw new Exception ( "DB Connection test faild." ) ; } } finally { db . clearErrors ( ) ; db . closeConnection ( ) ; } } System . out . println ( "DB connection tested successfully." ) ; CmsSetupDb db = null ; boolean dbExists = false ; if ( m_bean . isInitialized ( ) ) { if ( m_props . isCreateDb ( ) || m_props . isCreateTables ( ) ) { db = new CmsSetupDb ( m_bean . getWebAppRfsPath ( ) ) ; if ( m_bean . getDatabase ( ) . startsWith ( "oracle" ) || m_bean . getDatabase ( ) . startsWith ( "db2" ) || m_bean . getDatabase ( ) . startsWith ( "as400" ) ) { db . setConnection ( m_bean . getDbDriver ( ) , m_bean . getDbWorkConStr ( ) , m_bean . getDbConStrParams ( ) , m_bean . getDbWorkUser ( ) , m_bean . getDbWorkPwd ( ) ) ; } else { db . setConnection ( m_bean . getDbDriver ( ) , m_bean . getDbWorkConStr ( ) , m_bean . getDbConStrParams ( ) , m_bean . getDbCreateUser ( ) , m_bean . getDbCreatePwd ( ) , false ) ; dbExists = db . noErrors ( ) ; if ( dbExists ) { db . closeConnection ( ) ; } else { db . clearErrors ( ) ; } } if ( ! dbExists || m_props . isDropDb ( ) ) { db . closeConnection ( ) ; if ( ! m_bean . getDatabase ( ) . startsWith ( "db2" ) && ! m_bean . getDatabase ( ) . startsWith ( "as400" ) ) { db . setConnection ( m_bean . getDbDriver ( ) , m_bean . getDbCreateConStr ( ) , m_bean . getDbConStrParams ( ) , m_bean . getDbCreateUser ( ) , m_bean . getDbCreatePwd ( ) ) ; } } } } if ( ! m_props . isCreateDb ( ) && ! m_props . isCreateTables ( ) && ! dbExists ) { throw new Exception ( "You have not created the Alkacon OpenCms database." ) ; } if ( dbExists && m_props . isCreateTables ( ) && ! m_props . isDropDb ( ) && ( db != null ) ) { throw new Exception ( "You have selected to not drop existing DBs, but a DB with the given name exists." ) ; } if ( dbExists && m_props . isCreateDb ( ) && m_props . isDropDb ( ) && ( db != null ) ) { db . closeConnection ( ) ; db . setConnection ( m_bean . getDbDriver ( ) , m_bean . getDbWorkConStr ( ) , m_bean . getDbConStrParams ( ) , m_bean . getDbCreateUser ( ) , m_bean . getDbCreatePwd ( ) ) ; db . dropDatabase ( m_bean . getDatabase ( ) , m_bean . getReplacer ( ) ) ; if ( ! db . noErrors ( ) ) { for ( String error : db . getErrors ( ) ) { System . err . println ( error + "\n" ) ; System . err . println ( HR + "\n" ) ; } db . clearErrors ( ) ; throw new Exception ( "Error ocurred while dropping the DB!" ) ; } System . out . println ( "Database dropped successfully." ) ; } if ( m_props . isCreateDb ( ) && ( db != null ) ) { db . createDatabase ( m_bean . getDatabase ( ) , m_bean . getReplacer ( ) ) ; if ( ! db . noErrors ( ) ) { for ( String error : db . getErrors ( ) ) { System . err . println ( error + "\n" ) ; System . err . println ( HR + "\n" ) ; } db . clearErrors ( ) ; throw new Exception ( "Error ocurred while creating the DB!" ) ; } db . closeConnection ( ) ; System . out . println ( "Database created successfully." ) ; } if ( m_props . isCreateTables ( ) && ( db != null ) ) { db . setConnection ( m_bean . getDbDriver ( ) , m_bean . getDbWorkConStr ( ) , m_bean . getDbConStrParams ( ) , m_bean . getDbWorkUser ( ) , m_bean . getDbWorkPwd ( ) ) ; db . dropTables ( m_bean . getDatabase ( ) ) ; db . clearErrors ( ) ; db . closeConnection ( ) ; db . setConnection ( m_bean . getDbDriver ( ) , m_bean . getDbWorkConStr ( ) , m_bean . getDbConStrParams ( ) , m_bean . getDbWorkUser ( ) , m_bean . getDbWorkPwd ( ) ) ; db . createTables ( m_bean . getDatabase ( ) , m_bean . getReplacer ( ) ) ; if ( ! db . noErrors ( ) ) { for ( String error : db . getErrors ( ) ) { System . err . println ( error + "\n" ) ; System . err . println ( HR + "\n" ) ; } db . clearErrors ( ) ; throw new Exception ( "Error ocurred while creating tables." ) ; } db . closeConnection ( ) ; System . out . println ( "Tables created successfully." ) ; } if ( db != null ) { db . closeConnection ( ) ; } System . out . println ( "Database setup was successful." ) ; }
Creates DB and tables when necessary.<p>

@throws Exception in case creating DB or tables fails