File tree Expand file tree Collapse file tree 2 files changed +8
-15
lines changed
Expand file tree Collapse file tree 2 files changed +8
-15
lines changed Original file line number Diff line number Diff line change 2222 <artifactId >postgresql</artifactId >
2323 <version >9.4-1201-jdbc4</version >
2424 </dependency >
25+ <dependency >
26+ <groupId >com.heroku.sdk</groupId >
27+ <artifactId >heroku-jdbc</artifactId >
28+ <version >0.1.0</version >
29+ </dependency >
2530 </dependencies >
2631 <build >
2732 <plugins >
Original file line number Diff line number Diff line change 1111import spark .ModelAndView ;
1212import static spark .Spark .get ;
1313
14+ import com .heroku .sdk .jdbc .DatabaseUrl ;
15+
1416public class Main {
1517
1618 public static void main (String [] args ) {
@@ -31,7 +33,7 @@ public static void main(String[] args) {
3133 Connection connection = null ;
3234 Map <String , Object > attributes = new HashMap <>();
3335 try {
34- connection = getConnection ();
36+ connection = DatabaseUrl . extract (). getConnection ();
3537
3638 Statement stmt = connection .createStatement ();
3739 stmt .executeUpdate ("CREATE TABLE IF NOT EXISTS ticks (tick timestamp)" );
@@ -55,18 +57,4 @@ public static void main(String[] args) {
5557
5658 }
5759
58- private static Connection getConnection () throws URISyntaxException , SQLException {
59- URI dbUri = new URI (System .getenv ("DATABASE_URL" ));
60- int port = dbUri .getPort ();
61- String dbUrl = "jdbc:postgresql://" + dbUri .getHost () + ":" + port + dbUri .getPath ();
62-
63- if (dbUri .getUserInfo () != null ) {
64- String username = dbUri .getUserInfo ().split (":" )[0 ];
65- String password = dbUri .getUserInfo ().split (":" )[1 ];
66- return DriverManager .getConnection (dbUrl , username , password );
67- } else {
68- return DriverManager .getConnection (dbUrl );
69- }
70- }
71-
7260}
You can’t perform that action at this time.
0 commit comments