MCPcopy Create free account
hub / github.com/MaterializeInc/demos / App

Class App

connection-examples/java/insert.java:9–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7import java.sql.PreparedStatement;
8
9public class App {
10
11 private final String url = "jdbc:postgresql://MATERIALIZE_HOST:6875/materialize";
12 private final String user = "MATERIALIZE_USERNAME";
13 private final String password = "MATERIALIZE_PASSWORD";
14
15 /**
16 * Connect to Materialize
17 *
18 * @return a Connection object
19 */
20 public Connection connect() throws SQLException {
21 Properties props = new Properties();
22 props.setProperty("user", user);
23 props.setProperty("password", password);
24 props.setProperty("ssl","true");
25
26 return DriverManager.getConnection(url, props);
27
28 }
29
30 public void insert() {
31
32 try (Connection conn = connect()) {
33 String code = "GH";
34 String name = "Ghana";
35 PreparedStatement st = conn.prepareStatement("INSERT INTO countries(code, name) VALUES(?, ?)");
36 st.setString(1, code);
37 st.setString(2, name);
38 int rowsDeleted = st.executeUpdate();
39 System.out.println(rowsDeleted + " rows inserted.");
40 st.close();
41 } catch (SQLException ex) {
42 System.out.println(ex.getMessage());
43 }
44 }
45
46 public static void main(String[] args) {
47 App app = new App();
48 app.insert();
49 }
50}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected