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;
import logicTier.webWriter.*;

public class Main {

  public static void main(String[] args) {

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

    get("/hello", (req, res) -> "Hello World");
    //Test FreeMarker using index.html & account.html
    try{
		FtlWriter indexfw = new FtlWriter("index");
		indexfw.setParam("wzq", true, new String[]{"Pittsburgh", "PA", "Tele: 4153415605", "Zipcode: 15213"});
	}catch(Exception e){
		e.printStackTrace();
	}
	
	try{
		FtlWriter accountfw = new FtlWriter("account");
		accountfw.setParam("wangzhuoqun", true, new String[]{"Pittsburgh", "PA", "Tele: 4153415605", "Zipcode: 15213"});
	}catch(Exception e){
		e.printStackTrace();
	}


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

        Statement stmt = connection.createStatement();
        stmt.executeUpdate("CREATE TABLE IF NOT EXISTS ticks (tick timestamp)");
        stmt.executeUpdate("INSERT INTO ticks VALUES (now())");
        ResultSet rs = stmt.executeQuery("SELECT tick FROM ticks");

        ArrayList<String> output = new ArrayList<String>();
        while (rs.next()) {
          output.add( "Read from DB: " + rs.getTimestamp("tick"));
        }

        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());

  }

}

@@ -426,18 +426,16 @@
  %7B%0A%0A    
-//
 port(Int
@@ -473,16 +473,18 @@
 T%22)));%0A%09
+//
 port(888
@@ -521,16 +521,570 @@
 ublic%22);
+%0A    get(%22/%22, (req, res) -%3E%7B%0A    %09Map%3CString, Object%3E attributes = new HashMap%3C%3E();%0A        try %7B%0A          attributes.put(%22userName%22, %22wzq%22);%0A          attributes.put(%22isLogin%22, true);%0A          attributes.put(%22profile%22, new String%5B%5D%7B%22Pittsburgh%22, %22PA%22, %22Tele: 4153415605%22, %22Zipcode: 15213%22%7D);%0A          return new ModelAndView(attributes, %22index.ftl%22);%0A        %7D catch (Exception e) %7B%0A          attributes.put(%22message%22, %22There was an error: %22 + e);%0A          return new ModelAndView(attributes, %22error.ftl%22);%0A        %7D %0A    %7D, new FreeMarkerEngine());
 %0A%0A    ge
@@ -1179,16 +1179,18 @@
 nt.html%0A
+//
     try%7B
@@ -1186,24 +1186,26 @@
 %0A//    try%7B%0A
+//
 %09%09FtlWriter 
@@ -1238,16 +1238,18 @@
 ndex%22);%0A
+//
 %09%09indexf
@@ -1337,32 +1337,34 @@
 code: 15213%22%7D);%0A
+//
 %09%7Dcatch(Exceptio
@@ -1361,32 +1361,34 @@
 h(Exception e)%7B%0A
+//
 %09%09e.printStackTr
@@ -1394,16 +1394,18 @@
 race();%0A
+//
 %09%7D%0A%09%0A%09tr

fix itgit add . please