| 7 | import java.sql.PreparedStatement; |
| 8 | |
| 9 | public 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 | } |
nothing calls this directly
no outgoing calls
no test coverage detected