Valeu a dica já esta funcionando… mas agora estou com outro problema.
criei um metodo que recebe um String e me retorna um objeto… só que retorna o nome e cpf os outros campo vem null. o codigo do metodo e este:
public Cliente consulta(String cpf) throws ClienteException, ConectarException, SQLException {
// TODO Auto-generated method stub
Conectar objConectar = new Conectar();
ResultSet rs = null;
Cliente cl = null;
StringBuffer sql = new StringBuffer();
//SimpleDateFormat forma = new SimpleDateFormat("yyyy-MM-dd H:m:s");
try{
objConectar.getConnection();
/*sql.append("SELECT DISTINCT idCliente,nome,cpf " +
" FROM cliente " +
" WHERE cpf = '"+cpf+"'");
*/
sql.append("SELECT DISTINCT idcliente,nome,cpf " +
"FROM cliente " +
"WHERE cpf = '"+cpf+"'");
rs = objConectar.executeQuery(sql.toString());
rs.next();
cl = new Cliente();
cl.setIdcliente(rs.getInt(1));
cl.setNome(rs.getString(2));
cl.setCpf(rs.getString(3));
}catch (ConectarException e) {
// TODO: handle exception
throw new ClienteException("Falha na consulta do Lotação \n"+e.getMessage());
}finally{
sql = null;
objConectar = null;
}
return cl;
}
No JSP estou escrevendo assim codigo e este:
<%
String cpf = request.getParameter("cpf");
try{
Fachada cl = Fachada.getInstancia();
Cliente c = cl.consulta(cpf);
if (c.getCpf() == null){
%><script type="text/javascript">
alert("Digite o CPF do Cliente!");
</script><%
}else{
%>
<tr>
<td width="280"> <%= c.getIdcliente() %></td>
<td width="280"> <%= c.getNome() %></td>
<td width="280"> <%= c.getCpf() %></td>
</tr>
<%
}
}catch (ClienteException e) {
System.out.println(e.getMessage());
}
%>