Code example for PreparedStatement

Methods: executesetDatesetLongsetString

0
 
	public void atualiza(Contato contato) {
		String sql = "update contatos set nome = ?, email = ?, endereco = ?, 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 java.sql.Date(contato.getDataNascimento().getTimeInMillis()));
			stmt.setLong(5, contato.getId());
 
			stmt.execute();
		} catch (SQLException e) {
			throw new RuntimeException(e);
		} 
	} 
} 
Stop searching for code, let great code find you!  Add Codota to your java IDE