-1
I am trying to do a search in the mysql database doing a filter by date and is not bringing any results. On the screen below I was able to search for the other criteria
This is the code that’s doing the searches.
public void montaTabelaBusca() {
String criterio = " WHERE CLIENTE LIKE '" + inpClienteBusca.getText() + "%'"
+ " AND CARRO LIKE '" + inpCarroBusca.getText() + "%'"
+ " AND DESPESA LIKE '" + inpDespesaBusca.getText() + "%'"
+ " AND DATA LIKE '" + inpDataInicialBusca.getText() + "%'";
ArrayList<Venda> Vendas = VendaDao.getResultadoDaVenda(criterio);
String[] cabecalhoColunas = {"Id", "Data", "Cliente", "Carro", "Valor","Observação", "Despesa","Valor da despesa"};
modeloTabela = new DefaultTableModel(cabecalhoColunas, 0);
for (Venda v : Vendas) {
String[] novaLinha = {String.valueOf(v.getId()),Formatar("dd/MM/yyyy", v.getData()),String.valueOf(v.getCliente()),String.valueOf(v.getCarro()), Numeros.Formatar("#0.00", v.getValor()),String.valueOf(v.getObservacao()),String.valueOf(v.getDespesa()),Numeros.Formatar("#0.00", v.getValorDespesa())};
modeloTabela.addRow(novaLinha);
jtResultadoDaBusca.setModel(modeloTabela);
}
}
//getResulted
public static ArrayList<Venda> getResultadoDaVenda(String condicao) {
ResultSet resultado = ObjectFactory.getConexao().buscaSql("SELECT * FROM VENDA " + condicao);
try {
ArrayList<Venda> listagem = new ArrayList<>();
while (resultado.next()) {
Venda vendaPreenchida = preencheVenda(resultado);
listagem.add(vendaPreenchida);
}
return listagem;
} catch (SQLException ex) {
System.out.println("não eoncontrado!");
}
return null;
}
The result of this search is just a sale? If not, you cannot apply the model within the loop, otherwise nothing will result. Another thing, you say, "it doesn’t work", please, when drawing up a question, be more specific in the problem.
– user28595
Yes, the search result is a listing of that date. Thanks for the tip !
– Eduardo Krakhecke
How is this method
getResultadoDaVenda
? Why don’t you pass the parameters of the fields to him, instead of the query? That violates the responsibility of each class.– user28595
Yeah. I was trying, but it didn’t work
– Eduardo Krakhecke
Dude, don’t add big chunk of code in comment, see how it looks, you can’t read it like that.
– user28595
I’ll edit the question and put the code there
– Eduardo Krakhecke