Code example for PreparedStatement

Methods: execute, setBoolean, setDate

0
	public void insert(EntityInterface entity) throws SQLException {
		String sql = "INSERT INTO newsletter (date, enabled) VALUES (?, ?)";
		 
		Newsletter newsletter = (Newsletter) entity;
		PreparedStatement stm = this.db.prepareStatement(sql);
		stm.setDate(1, new java.sql.Date(newsletter.getDate().getTime()));
		stm.setBoolean(2, newsletter.isEnabled());
		stm.execute();
	} 
 
	@Override 
	public void delete(EntityInterface entity) throws SQLException {
		String sql = "DELETE FROM newsletter WHERE id = ?";
		 
		Newsletter newsletter = (Newsletter) entity;
		PreparedStatement stm = this.db.prepareStatement(sql);
		stm.setInt(1, newsletter.getId());
		stm.execute();
	} 
 
	@Override