How to convert a JTextField
component to type Date
? How to do research?
How to create a query for the database by returning a list of requests according to a date range?
Follow the code currently used:
if (opcaoBusca.getSelectedIndex() == 0) {
JOptionPane.showMessageDialog(null,
"Escolha uma Opção de Busca!");
} else if (opcaoBusca.getSelectedIndex() == 1) {
RS = stmt.executeQuery("select numped FROM PCPEDC WHERE DATA > '10/01/2014' and numped = " + BuscaCodigo);
while (RS.next()) {
int Num = RS.getInt("numped");
consulta = false;
JOptionPane.showMessageDialog(null, "Dados Encontrado!!!!");
}
} else if (opcaoBusca.getSelectedIndex() == 2) {
RS = stmt.executeQuery("SELECT Data FROM PCPEDC WHERE Data BETWEEN " + Dtincial + "AND" + Dtfinal);
while (RS.next()) {
int Num = RS.getInt("numped");
//...
}
}
//mascara para os campos //
Dtincial = new JFormattedTextField(DateFormat.getDateInstance( ));
try {
javax.swing.text.MaskFormatter data= new javax.swing.text.MaskFormatter("##/##/####");
Dtincial = new javax.swing.JFormattedTextField(data);
} catch (Exception e){
}
Dtincial.setColumns(10);
Dtfinal = new JFormattedTextField(DateFormat.getDateInstance( ));
try {
javax.swing.text.MaskFormatter data= new javax.swing.text.MaskFormatter("##/##/####");
Dtfinal = new javax.swing.JFormattedTextField(data);
} catch (Exception e){
}
//declaração dos atributos
private JTextField Dtincial;
private JTextField Dtfinal;