// if (Objects.equal(sqlState, "42P04")) {
// log.info("Database already exists");
// return false;
// }
log.info("Unknown code: " + sqlState);
throw new OpsException("Error checking if database exists", e);
}
}
try {
String sql = "CREATE DATABASE " + databaseName;
String maskedSql = sql;
// No point trying to connect to the database we're trying to create!
String runInDatabase = "postgres";
execute((SshOpsTarget) target, username, password, runInDatabase, sql, maskedSql);
return true;
} catch (SQLException e) {
String sqlState = e.getSQLState();
// if (execution.getExitCode() == 1 && execution.getStdErr().contains("already exists")) {
// log.info("Database already exists");
// return;
// }
if (Objects.equal(sqlState, "XX000")) {
log.info("Database already exists");
return false;
}
if (Objects.equal(sqlState, "42P04")) {
log.info("Database already exists");
return false;
}
log.info("Unknown code: " + sqlState);
throw new OpsException("Error creating database", e);
}
}