Consulta Datas

1 resposta
N

Olá a todos.

Tenho um campo em uma tabela Access com o formato ‘14/06/2011 14:29:25’.

Estou tentando realizar um SELECT entre datas e está havendo o seguinte erro: “unparseable date”.

Alguém pode me ajudar?

Segue abaixo o código:

public void ConsultaDatas(){   

    try
    {    

    Date DataInicial = (Date) new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").parse(JFormattedTextFieldDataInicial.getText());
    Date DataFinal = (Date) new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").parse(JFormattedTextFieldDataInicial.getText());

    Connection con = Conexao.getConnection();
    Statement st = con.createStatement();
    ResultSet rs = st.executeQuery("SELECT * FROM Vendas WHERE HoraInicioCupom BETWEEN "+ DataInicial +" AND "+ DataFinal +"");

    while(rs.next()){  
   
    Date d = (Date) new SimpleDateFormat("dd/MM/yyyy").parse(rs.getString("HoraInicioCupom"));
    String cupom = rs.getString("contCOOCupom");
    String cod = rs.getString("Codigo");
    String descricao = rs.getString("Descricao");
    int qtd = rs.getInt("Quantidade");
    Double vunit = rs.getDouble("ValorUnitario");
    Double vtot = rs.getDouble("ValorTotal");

    modelo.addRow(new Object[]{cupom,d,cod,descricao,qtd,vunit,vtot});   
    JLabelInformacao.setText(""+ JTableDados.getModel().getRowCount() + " registros encontrados");

    }  

    rs.close();
    con.close();     
        
    }catch(SQLException e){
    JOptionPane.showMessageDialog(null,"Erro: "+e.getMessage());
    }catch(Exception event){    
    JOptionPane.showMessageDialog(null,"Erro: "+event.getMessage());
    }}

1 Resposta

F

Tem como dar uma identada? Tá difícil de ler assim…

Criado 3 de abril de 2012
Ultima resposta 3 de abr. de 2012
Respostas 1
Participantes 2