private boolean createTableIfNotExists() throws HandlerException {
    boolean result = false;
    try (Connection conn = getConnection()) {
      StringBuilder query = new StringBuilder();
      String tableNameWithSchema = (!StringUtils.isEmpty(schemaName)) ? (schemaName + "." + tableName) : tableName;

      if (isOracleDatabase()) {
        // Create table if Oracle Database
        //String values[] = tableName.split("\\.");
        query.append("select count(*) from all_tables where table_name = upper('")
          .append(tableName).append("')");
        try (PreparedStatement statement = conn.prepareStatement(query.toString())) {
          result = statement.execute();
        }
        if (result == false) {
          query.append("create table ").append(tableNameWithSchema).append(" (")
            .append("identifier VARCHAR2(200) NOT NULL,")
            .append("timestamp TIMESTAMP NOT NULL,")
            .append("actor VARCHAR2(200) NOT NULL,").append("origin VARCHAR2(200),")
            .append("action VARCHAR2(200) NOT NULL,").append("elements CLOB")
            .append(");");
        }
      } else if (isHSQLDatabase()) {
        // Create Table if HSQLDB database
        query.append("create table if not exists ").append(tableNameWithSchema).append(" (")
          .append("identifier VARCHAR(200) NOT NULL,")
          .append("timestamp TIMESTAMP NOT NULL,")
          .append("actor VARCHAR(200) NOT NULL,").append("origin VARCHAR(200),")
          .append("action VARCHAR(200) NOT NULL,").append("elements LONGVARCHAR")
          .append(");");
        try (PreparedStatement statement = conn.prepareStatement(query.toString())) {
          result = statement.execute();
        }
      } else if (isMySQLDatabase()) {
        // Create table if MySQL database
        query.append("create table if not exists ").append(tableNameWithSchema).append(" (")
          .append("identifier VARCHAR(200) NOT NULL,")
          .append("timestamp TIMESTAMP NOT NULL,")
          .append("actor VARCHAR(200) NOT NULL,").append("origin VARCHAR(200),")
          .append("action VARCHAR(200) NOT NULL,").append("elements TEXT")
          .append(");");
        try (PreparedStatement statement = conn.prepareStatement(query.toString())) {
          result = statement.execute();
        }
      } else if (isSQLServerDatabase()) {
        // Create table if SQLServer database
        query.append(" IF OBJECT_ID(N'"+tableNameWithSchema+"', N'U') IS NULL BEGIN ");
        query.append("create table ").append(tableNameWithSchema).append(" (")
          .append("identifier VARCHAR(200) NOT NULL,")
          .append("timestamp DATETIME NOT NULL,")
          .append("actor VARCHAR(200) NOT NULL,").append("origin VARCHAR(200),")
          .append("action VARCHAR(200) NOT NULL,").append("elements TEXT")
          .append(");");
        query.append(" END ");
        try (PreparedStatement statement = conn.prepareStatement(query.toString())) {
          result = statement.execute();
        }
      } else {
        query.append("create table if not exists ").append(tableNameWithSchema).append(" (")
          .append("identifier VARCHAR(200) NOT NULL,")
          .append("timestamp TIMESTAMP NOT NULL,")
          .append("actor VARCHAR(200) NOT NULL,").append("origin VARCHAR(200),")
          .append("action VARCHAR(200) NOT NULL,").append("elements VARCHAR(70000)")
          .append(");");
        try (PreparedStatement statement = conn.prepareStatement(query.toString())) {
          result = statement.execute();
        }
      }
      return result;
    } catch (SQLException e) {
      throw new HandlerException("SQL Exception", DatabaseAuditHandler.class, e);
    }
  }
private boolean createTableIfNotExists ( ) throws HandlerException { boolean result = false ; try ( Connection conn = getConnection ( ) ) { StringBuilder query = new StringBuilder ( ) ; String tableNameWithSchema = ( ! StringUtils . isEmpty ( schemaName ) ) ? ( schemaName + "." + tableName ) : tableName ; if ( isOracleDatabase ( ) ) { query . append ( "select count(*) from all_tables where table_name = upper('" ) . append ( tableName ) . append ( "')" ) ; try ( PreparedStatement statement = conn . prepareStatement ( query . toString ( ) ) ) { result = statement . execute ( ) ; } if ( result == false ) { query . append ( "create table " ) . append ( tableNameWithSchema ) . append ( " (" ) . append ( "identifier VARCHAR2(200) NOT NULL," ) . append ( "timestamp TIMESTAMP NOT NULL," ) . append ( "actor VARCHAR2(200) NOT NULL," ) . append ( "origin VARCHAR2(200)," ) . append ( "action VARCHAR2(200) NOT NULL," ) . append ( "elements CLOB" ) . append ( ");" ) ; } } else if ( isHSQLDatabase ( ) ) { query . append ( "create table if not exists " ) . append ( tableNameWithSchema ) . append ( " (" ) . append ( "identifier VARCHAR(200) NOT NULL," ) . append ( "timestamp TIMESTAMP NOT NULL," ) . append ( "actor VARCHAR(200) NOT NULL," ) . append ( "origin VARCHAR(200)," ) . append ( "action VARCHAR(200) NOT NULL," ) . append ( "elements LONGVARCHAR" ) . append ( ");" ) ; try ( PreparedStatement statement = conn . prepareStatement ( query . toString ( ) ) ) { result = statement . execute ( ) ; } } else if ( isMySQLDatabase ( ) ) { query . append ( "create table if not exists " ) . append ( tableNameWithSchema ) . append ( " (" ) . append ( "identifier VARCHAR(200) NOT NULL," ) . append ( "timestamp TIMESTAMP NOT NULL," ) . append ( "actor VARCHAR(200) NOT NULL," ) . append ( "origin VARCHAR(200)," ) . append ( "action VARCHAR(200) NOT NULL," ) . append ( "elements TEXT" ) . append ( ");" ) ; try ( PreparedStatement statement = conn . prepareStatement ( query . toString ( ) ) ) { result = statement . execute ( ) ; } } else if ( isSQLServerDatabase ( ) ) { query . append ( " IF OBJECT_ID(N'" + tableNameWithSchema + "', N'U') IS NULL BEGIN " ) ; query . append ( "create table " ) . append ( tableNameWithSchema ) . append ( " (" ) . append ( "identifier VARCHAR(200) NOT NULL," ) . append ( "timestamp DATETIME NOT NULL," ) . append ( "actor VARCHAR(200) NOT NULL," ) . append ( "origin VARCHAR(200)," ) . append ( "action VARCHAR(200) NOT NULL," ) . append ( "elements TEXT" ) . append ( ");" ) ; query . append ( " END " ) ; try ( PreparedStatement statement = conn . prepareStatement ( query . toString ( ) ) ) { result = statement . execute ( ) ; } } else { query . append ( "create table if not exists " ) . append ( tableNameWithSchema ) . append ( " (" ) . append ( "identifier VARCHAR(200) NOT NULL," ) . append ( "timestamp TIMESTAMP NOT NULL," ) . append ( "actor VARCHAR(200) NOT NULL," ) . append ( "origin VARCHAR(200)," ) . append ( "action VARCHAR(200) NOT NULL," ) . append ( "elements VARCHAR(70000)" ) . append ( ");" ) ; try ( PreparedStatement statement = conn . prepareStatement ( query . toString ( ) ) ) { result = statement . execute ( ) ; } } return result ; } catch ( SQLException e ) { throw new HandlerException ( "SQL Exception" , DatabaseAuditHandler . class , e ) ; } }
Creates the table in the database based on the table name given through
constructor. This supports to different databases including Oracle,
MySQL, Postgress and HSQLDB.

@return true, if successful
@throws HandlerException
the handler exception