-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrds.java
More file actions
34 lines (33 loc) · 1.17 KB
/
rds.java
File metadata and controls
34 lines (33 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class Cl {
private static Connection getRemoteConnection() {
if (System.getenv("RDS_HOSTNAME") != null) {
try {
Class.forName("org.postgresql.Driver");
String dbName = "myRDSdb";
String userName = "foo";
String password = "foobarbaz";
String hostname = System.getenv("RDS_HOSTNAME");
String port = System.getenv("RDS_PORT");
String jdbcUrl = "jdbc:postgresql://" + hostname + ":" + port + "/" + dbName + "?user=" + userName + "&password=" + password;
logger.trace("Getting remote connection with connection string from environment variables.");
Connection con = DriverManager.getConnection(jdbcUrl);
logger.info("Remote connection successful.");
return con;
}
catch (ClassNotFoundException e) { logger.warn(e.toString());}
catch (SQLException e) { logger.warn(e.toString());}
}
return null;
}
String saveInvoiceData(string data, int id){
try{
Connection con = getRemoteConnection();
Statement stmt = con.createStatement();
rs = stmt.executeQuery("UPDATE INVOICE SET data = '" + data + "' WHERE ID = " + id);
return rs.getString("Id");
} catch (Exception exc){
//
}
return null;
}
}