Created
March 12, 2010 03:19
-
-
Save qmx/329991 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ConsultaDAO { | |
// .... | |
// Aqui seria melhor devolver um contato, não? Afinal queremos buscar um contato... | |
public void consulta (int id){ | |
try{ | |
// eu realmente não preciso de uma lista.. | |
List<Contato> contatos = new ArrayList<Contato>(); (Tenho dúvida se precisa de um List mesmo). | |
PreparedStatement stmt = connection.prepareStatement("select * from contatos where id=?"); | |
ResultSet rs = stmt.executeQuery(); | |
while(rs.next()){ | |
// Aqui dentro você já tem um contato, neste caso o que faltou foi: | |
Contato contato = new Contato(); | |
contato.setId(rs.getLong("id")); | |
// continue chamando os setters aqui, por exemplo, contato.setNome(rs.getString("nome")); | |
// finalmente, devolva este contato: | |
// return contato; | |
} | |
rs.close(); | |
stmt.close(); | |
}catch(SQLException e){ | |
throw new RuntimeException(e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment