package com.example.bot.spring;

import org.apache.commons.dbcp.BasicDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import java.util.Map;
import javax.sql.DataSource;
import java.net.URI;
import java.net.URISyntaxException;
import java.sql.*;
import java.util.ArrayList;

@Configuration
@ComponentScan(basePackages = "com.example.bot.spring")
public class MainConfig {

	@Autowired
	private DataSource dataSource;

	@RequestMapping("/db")
	String db(Map<String, Object> model) {
	    try (Connection connection = dataSource.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"));
	      }

	      model.put("records", output);
	      return "db";
	    } catch (Exception e) {
	      model.put("message", e.getMessage());
	      return "error";
	    }
	}
}
import org.apache.commons.dbcp.BasicDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

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

@Configuration
@ComponentScan(basePackages = "com.heroku.example")
public class MainConfig {

    @Bean
    public BasicDataSource dataSource() throws URISyntaxException {
        URI dbUri = new URI(System.getenv("DATABASE_URL"));

        String username = dbUri.getUserInfo().split(":")[0];
        String password = dbUri.getUserInfo().split(":")[1];
        String dbUrl = "jdbc:postgresql://" + dbUri.getHost() + dbUri.getPath();

        BasicDataSource basicDataSource = new BasicDataSource();
        basicDataSource.setUrl(dbUrl);
        basicDataSource.setUsername(username);
        basicDataSource.setPassword(password);

        return basicDataSource;
    }
}
@@ -30,1505 +30,8 @@
 g;%0A%0A
-import org.apache.commons.dbcp.BasicDataSource;%0Aimport org.springframework.context.annotation.Bean;%0Aimport org.springframework.context.annotation.ComponentScan;%0Aimport org.springframework.context.annotation.ConfigurationProperties;%0Aimport org.springframework.context.annotation.Configuration;%0Aimport org.springframework.web.bind.annotation.RequestMapping;%0Aimport org.springframework.beans.factory.annotation.Autowired;%0Aimport org.springframework.beans.factory.annotation.Value;%0Aimport java.util.Map;%0Aimport javax.sql.DataSource;%0Aimport java.net.URI;%0Aimport java.net.URISyntaxException;%0Aimport java.sql.*;%0Aimport java.util.ArrayList;%0A%0A@Configuration%0A@ComponentScan(basePackages = %22com.example.bot.spring%22)%0Apublic class MainConfig %7B%0A%0A%09@Autowired%0A%09private DataSource dataSource;%0A%0A%09@RequestMapping(%22/db%22)%0A%09String db(Map%3CString, Object%3E model) %7B%0A%09    try (Connection connection = dataSource.getConnection()) %7B%0A%09      Statement stmt = connection.createStatement();%0A%09      stmt.executeUpdate(%22CREATE TABLE IF NOT EXISTS ticks (tick timestamp)%22);%0A%09      stmt.executeUpdate(%22INSERT INTO ticks VALUES (now())%22);%0A%09      ResultSet rs = stmt.executeQuery(%22SELECT tick FROM ticks%22);%0A%0A%09      ArrayList%3CString%3E output = new ArrayList%3CString%3E();%0A%09      while (rs.next()) %7B%0A%09        output.add(%22Read from DB: %22 + rs.getTimestamp(%22tick%22));%0A%09      %7D%0A%0A%09      model.put(%22records%22, output);%0A%09      return %22db%22;%0A%09    %7D catch (Exception e) %7B%0A%09      model.put(%22message%22, e.getMessage());%0A%09      return %22error%22;%0A%09    %7D%0A%09%7D%0A%7D%0A
 impo
@@ -248,16 +248,16 @@
 ration;%0A
+
 %0Aimport 
@@ -361,22 +361,26 @@
 com.
-heroku.
 example
+.bot.spring
 %22)%0Ap

Add existing file