-
Notifications
You must be signed in to change notification settings - Fork 9
/
query.java
48 lines (39 loc) · 1.28 KB
/
query.java
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
import java.sql.ResultSet;
import java.sql.Statement;
public class App {
private final String url = "jdbc:postgresql://MATERIALIZE_HOST:6875/materialize";
private final String user = "MATERIALIZE_USERNAME";
private final String password = "MATERIALIZE_PASSWORD";
/**
* Connect to Materialize
*
* @return a Connection object
*/
public Connection connect() throws SQLException {
Properties props = new Properties();
props.setProperty("user", user);
props.setProperty("password", password);
props.setProperty("ssl","true");
return DriverManager.getConnection(url, props);
}
public void query() {
String SQL = "SELECT * FROM my_view";
try (Connection conn = connect();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(SQL)) {
while (rs.next()) {
System.out.println(rs.getString("my_column"));
}
} catch (SQLException ex) {
System.out.println(ex.getMessage());
}
}
public static void main(String[] args) {
App app = new App();
app.query();
}
}