import java.sql.*;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Map;

import java.net.URI;
import java.net.URISyntaxException;

import static spark.Spark.*;
import spark.template.freemarker.FreeMarkerEngine;
import spark.ModelAndView;
import static spark.Spark.get;

import com.heroku.sdk.jdbc.DatabaseUrl;

public class Main {

  public static void main(String[] args) {

    port(Integer.valueOf(System.getenv("PORT")));
    staticFileLocation("/public");

    get("/hello", (req, res) -> "Hello World");

    get("/", (request, response) -> {
            Map<String, Object> attributes = new HashMap<>();
            attributes.put("message", "Hello World!");

            return new ModelAndView(attributes, "index.ftl");
        }, new FreeMarkerEngine());

    get("/db", (req, res) -> {
      Connection connection = null;
      Map<String, Object> attributes = new HashMap<>();
      try {
        connection = DatabaseUrl.extract().getConnection();

        Statement stmt = connection.createStatement();
       
        ResultSet rs = stmt.executeQuery("SELECT * FROM salesforcedev.user");

        ArrayList<String> output = new ArrayList<String>();
        while (rs.next()) {
          output.add( "Read from DB: " + rs.getString("name")+"-"+ rs.getString("sfid"));
        }

        attributes.put("results", output);
        return new ModelAndView(attributes, "db.ftl");
      } catch (Exception e) {
        attributes.put("message", "There was an error: " + e);
        return new ModelAndView(attributes, "error.ftl");
      } finally {
        if (connection != null) try{connection.close();} catch(SQLException e){}
      }
    }, new FreeMarkerEngine());

  }

}

@@ -567,24 +567,61 @@
  -%3E %7B%0A      
+       Connection connection = null;%0A
       Map%3CSt
@@ -674,62 +674,597 @@
     
-      attributes.put(%22message%22, %22Hello World!%22);%0A%0A    
+try %7B%0A        connection = DatabaseUrl.extract().getConnection();%0A%0A        Statement stmt = connection.createStatement();%0A       %0A        ResultSet rs = stmt.executeQuery(%22SELECT * FROM salesforcedev.user%22);%0A%0A        ArrayList%3CString%3E output = new ArrayList%3CString%3E();%0A        while (rs.next()) %7B%0A          output.add( %22Read from DB: %22 + rs.getString(%22name%22)+%22-%22+ rs.getString(%22sfid%22));%0A        %7D%0A%0A        attributes.put(%22results%22, output);%0A        return new ModelAndView(attributes, %22db.ftl%22);%0A      %7D catch (Exception e) %7B%0A        attributes.put(%22message%22, %22There was an error: %22 + e);%0A
     
@@ -1308,13 +1308,13 @@
 s, %22
-index
+error
 .ftl
@@ -1317,24 +1317,127 @@
 .ftl%22);%0A    
+  %7D finally %7B%0A        if (connection != null) try%7Bconnection.close();%7D catch(SQLException e)%7B%7D%0A      %7D%0A
     %7D, new F

Update Main.java