| 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(); |