Skip to content

Commit 527feec

Browse files
committed
Update to use ElephantSQL and use manifest v6
1 parent 95d960c commit 527feec

File tree

3 files changed

+16
-25
lines changed

3 files changed

+16
-25
lines changed

app/src/com/ibm/bluemix/samples/PostgreSQLClient.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
/*-------------------------------------------------------------------*/
4343
package com.ibm.bluemix.samples;
4444

45+
import java.net.URI;
4546
import java.sql.Connection;
4647
import java.sql.DriverManager;
4748
import java.sql.PreparedStatement;
@@ -183,23 +184,19 @@ private static Connection getConnection() throws Exception {
183184
// We don't know exactly what the service is called, but it will contain "postgresql"
184185
for (Object key : vcap.keySet()) {
185186
String keyStr = (String) key;
186-
if (keyStr.toLowerCase().contains("postgresql")) {
187+
if (keyStr.toLowerCase().contains("elephantsql")) {
187188
service = (JSONObject) ((JSONArray) vcap.get(keyStr)).get(0);
188189
break;
189190
}
190191
}
191192

192193
if (service != null) {
193194
JSONObject creds = (JSONObject) service.get("credentials");
194-
String name = (String) creds.get("name");
195-
String host = (String) creds.get("host");
196-
Long port = (Long) creds.get("port");
197-
String user = (String) creds.get("user");
198-
String password = (String) creds.get("password");
199-
200-
String url = "jdbc:postgresql://" + host + ":" + port + "/" + name;
201-
202-
return DriverManager.getConnection(url, user, password);
195+
URI uri = URI.create((String) creds.get("uri"));
196+
String url = "jdbc:postgresql://" + uri.getHost() + ":" + uri.getPort() + uri.getPath();
197+
String username = uri.getUserInfo().split(":")[0];
198+
String password = uri.getUserInfo().split(":")[1];
199+
return DriverManager.getConnection(url, username, password);
203200
}
204201
}
205202

manifest.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
applications:
3+
- name: JavaUpload
4+
memory: 256M #The maximum memory to allocate to each application instance
5+
instances: 1 #The number of instances of the application to start
6+
host: JavaUpload-${random-word} #Hostname for app routing. Unique to domain
7+
services:
8+
- java-pg #Identifier for ElephantSQL service, must be provisioned before push
9+

manifest.yml.v5

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)