content: 
  import java.io.IOException;
  import java.sql.*;
  
  public class Main {
  
      private static final String JDBC_DRIVER = "org.postgresql.Driver";
      private static final String DB_URL = "jdbc:postgresql://127.0.0.1:7654/buptlab_database";
      private static final String USERNAME = "bupt_dba";
      private static final String PASSWORD = "i_am_from_bupt666";
  
      public static void main(String[] args) {
          System.out.println("Java version: " + System.getProperty("java.version"));
  
          try {
              Class.forName(JDBC_DRIVER);
              try (Connection conn = DriverManager.getConnection(DB_URL, USERNAME, PASSWORD)) {
                  System.out.println("Database connected successfully!");
  
                  executeTasks(conn);
              } catch (SQLException e) {
                  System.err.println("Connection Failed. Check output console");
                  e.printStackTrace();
              }
          } catch (ClassNotFoundException e) {
              System.err.println("PostgreSQL JDBC Driver not found!!");
          }
      }
  
      private static void executeTasks(Connection conn) {
          try {
              System.out.println("Executing Task 1...");
              task1(conn);
  
              System.out.println("Executing Task 2...");
              task2(conn);
  
              System.out.println("Executing Task 3...");
              task3(conn);
  
              System.out.println("Executing Task 4...");
              task4(conn);
          } catch (SQLException | IOException e) {
              System.err.println("Task Failed. Check output console");
              e.printStackTrace();
          }
      }
  
      private static void task1(Connection conn) throws SQLException, IOException {
          String sql = "SELECT n_nationkey, n_name, n_regionkey, n_comment FROM nation";
          try (Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(sql)) {
  
              System.out.printf("%-12s %-15s %-12s %s\n", "nation_key", "name", "region_key", "comment");
              while (rs.next()) {
                  int nationkey = rs.getInt("n_nationkey");
                  String name = rs.getString("n_name").trim();
                  int regionkey = rs.getInt("n_regionkey");
                  String comment = rs.getString("n_comment").trim();
                  System.out.printf(" %-5d %-15s %-5d %s%n", nationkey, name, regionkey, comment);
              }
          }
      }
  
      private static void task2(Connection conn) throws SQLException, IOException {
          String sqlInsert = "INSERT INTO nation (n_nationkey, n_name, n_regionkey) VALUES (25, 'South Korea', 3)";
          String sqlSelect = "SELECT * FROM nation WHERE n_nationkey = 25";
          try (Statement stmt = conn.createStatement()) {
              stmt.execute(sqlInsert);
              try (ResultSet rs = stmt.executeQuery(sqlSelect)) {
                  if (rs.next()) {
                      int nationkey = rs.getInt("n_nationkey");
                      String name = rs.getString("n_name");
                      int regionkey = rs.getInt("n_regionkey");
                      String comment = rs.getString("n_comment");
                      System.out.printf("Inserted Data - nationkey: %-5d name: %-15s regionkey: %-5d comment: %s\n",
                              nationkey, name.trim(), regionkey, comment);
                      System.out.println("Insert data successfully!");
                  }
              }
          }
      }
  
      private static void task3(Connection conn) throws SQLException, IOException {
          String sqlUpdate = "UPDATE nation SET n_regionkey = 2 WHERE n_nationkey = 25";
          String sqlSelect = "SELECT * FROM nation WHERE n_nationkey = 25";
          try (Statement stmt = conn.createStatement()) {
              stmt.execute(sqlUpdate);
              try (ResultSet rs = stmt.executeQuery(sqlSelect)) {
                  if (rs.next()) {
                      int nationkey = rs.getInt("n_nationkey");
                      String name = rs.getString("n_name");
                      int regionkey = rs.getInt("n_regionkey");
                      String comment = rs.getString("n_comment");
                      System.out.printf("Updated Data - nationkey: %-5d name: %-15s regionkey: %-5d comment: %s\n",
                              nationkey, name.trim(), regionkey, comment);
                      System.out.println("Update data successfully!");
                  }
              }
          }
      }
  
      private static void task4(Connection conn) throws SQLException, IOException {
          String sqlDelete = "DELETE FROM nation WHERE n_nationkey = 25";
          String sqlSelect = "SELECT * FROM nation WHERE n_nationkey = 25";
          try (Statement stmt = conn.createStatement()) {
              stmt.execute(sqlDelete);
              try (ResultSet rs = stmt.executeQuery(sqlSelect)) {
                  if (!rs.next()) {
                      System.out.println("Delete data successfully!");
                  }
              }
          }
      }
  }
  