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";
	    }
	}
}
@@ -1522,8 +1522,965 @@
   %7D%0A%09%7D%0A%7D
+%0Aimport org.apache.commons.dbcp.BasicDataSource;%0Aimport org.springframework.context.annotation.Bean;%0Aimport org.springframework.context.annotation.ComponentScan;%0Aimport org.springframework.context.annotation.Configuration;%0A%0Aimport java.net.URI;%0Aimport java.net.URISyntaxException;%0A%0A@Configuration%0A@ComponentScan(basePackages = %22com.heroku.example%22)%0Apublic class MainConfig %7B%0A%0A    @Bean%0A    public BasicDataSource dataSource() throws URISyntaxException %7B%0A        URI dbUri = new URI(System.getenv(%22DATABASE_URL%22));%0A%0A        String username = dbUri.getUserInfo().split(%22:%22)%5B0%5D;%0A        String password = dbUri.getUserInfo().split(%22:%22)%5B1%5D;%0A        String dbUrl = %22jdbc:postgresql://%22 + dbUri.getHost() + dbUri.getPath();%0A%0A        BasicDataSource basicDataSource = new BasicDataSource();%0A        basicDataSource.setUrl(dbUrl);%0A        basicDataSource.setUsername(username);%0A        basicDataSource.setPassword(password);%0A%0A        return basicDataSource;%0A    %7D%0A%7D

Add existing file