How to do a sql search in java that involves multiple arguments? Example: I want to research all people with Angolan nationality, Computer Science course and two or more years of professional experience.
I'm using this way: select * from candidato where nome like ?
, but when I increase more fields it returns error.
This is my search method:
public List<Dados_Cadastro> getLista(String nome) throws SQLException{
String sql="select * from candidato where nome like ?";
PreparedStatement stm = this.conexao.prepareStatement(sql);
stm.setString(1, nome);
ResultSet rs = stm.executeQuery();
List<Dados_Cadastro>nova_lista = new ArrayList<Dados_Cadastro>();
while(rs.next()){
Dados_Cadastro cadastro =new Dados_Cadastro();
cadastro.setNome_cadastro(rs.getString("nome"));
cadastro.setGenero_cadastro(rs.getString("genero"));
cadastro.setData_nasc_cadastro(rs.getString("nasc"));
cadastro.setCbox_nacion_cadastro(rs.getString("nacionalidade"));
cadastro.setCbox_nivel_cadastro(rs.getString("n_academico"));
cadastro.setCurso_cadastro(rs.getString("curso"));
cadastro.setEmpresa_cadastro(rs.getString("empresa"));
cadastro.setCbox_exper_cadastro(rs.getString("experiencia"));
cadastro.setIdent(Long.valueOf(rs.getString("ident")));
nova_lista.add(cadastro);
}
rs.close();
stm.close();
return nova_lista;
}