private int showCreateDatabase(DataOutputStream outStream) throws Exception {
    Database database = context.getDb().getDatabase(desc.getDatabaseName());

    StringBuilder createDbCommand = new StringBuilder();
    createDbCommand.append("CREATE DATABASE `").append(database.getName()).append("`\n");
    if (database.getDescription() != null) {
      createDbCommand.append("COMMENT\n  '");
      createDbCommand.append(HiveStringUtils.escapeHiveCommand(database.getDescription())).append("'\n");
    }
    createDbCommand.append("LOCATION\n  '");
    createDbCommand.append(database.getLocationUri()).append("'\n");
    if (database.getManagedLocationUri() != null) {
      createDbCommand.append("MANAGEDLOCATION\n  '");
      createDbCommand.append(database.getManagedLocationUri()).append("'\n");
    }
    String propertiesToString = ShowUtils.propertiesToString(database.getParameters(), Collections.emptySet());
    if (!propertiesToString.isEmpty()) {
      createDbCommand.append("WITH DBPROPERTIES (\n");
      createDbCommand.append(propertiesToString).append(")\n");
    }

    outStream.write(createDbCommand.toString().getBytes(StandardCharsets.UTF_8));
    return 0;
  }
Operation process showing the creation of a database.
ql/src/java/org/apache/hadoop/hive/ql/ddl/database/showcreate/ShowCreateDatabaseOperation.java