Code example for PreparedStatement

Methods: executesetDatesetLongsetStringclose

0
	public void altera(Contato contato) {
		String sql = "UPDATE contatos SET nome=?, email=?, enderco=?, dataNascimento=? WHERE id=?";
		 
		try { 
			PreparedStatement stmt = this.connection.prepareStatement(sql);
			stmt.setString(1, contato.getNome());
			stmt.setString(2, contato.getEmail());
			stmt.setString(3, contato.getEndereco());
			stmt.setDate(4, new Date(contato.getDataNascimento().getTimeInMillis()));
			stmt.setLong(5, contato.getId());
			stmt.execute();
			stmt.close();
		} catch (SQLException e) {
			throw new RuntimeException(e);
		} 
	} 
} 
Connect your IDE to all the code out there  Get Codota for Java