@Override public void update(int id, Feed feed) { try { Connection cn = null; try { JdbcConnection connection = JdbcConnection.getInstance(); cn = connection.getConnection(); PreparedStatement st = null; try { st = cn.prepareStatement("UPDATE feed SET (typeFeed = ?, valueFeed = ?) WHERE idFeed = ?"); st.setString(1, feed.name()); st.setString(2, feed.getValueFeed()); st.setInt(3, id); st.executeUpdate(); } finally { if (st != null) st.close(); st = null; } } finally { if (cn != null) cn.close(); cn = null; } } catch (SQLException e) { e.printStackTrace(); } }
@Override public void create(Feed feed) { try { Connection cn = null; try { cn = JdbcConnection.getInstance().getConnection(); PreparedStatement st = null; try { st = cn.prepareStatement( "INSERT INTO feed (typeFeed, valueFeed) values (?, ?)", Statement.RETURN_GENERATED_KEYS); st.setString(1, feed.name()); st.setString(2, feed.getValueFeed()); st.executeUpdate(); } finally { if (st != null) st.close(); st = null; } } finally { if (cn != null) cn.close(); cn = null; } } catch (SQLException e) { e.printStackTrace(); } }