Help needed how to select all entries from a table between dates

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Help needed how to select all entries from a table between dates

Abdul Qadir
How to get dates from 2 different jDateChooser and use them in query like
select *from records  where date between jDateChooser and jDateChooser

Help will be very much appreciated and thanks in advance
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Help needed how to select all entries from a table between dates

merl
private void sqltable(){
       
        try{
        String sql = "SELECT * FROM Table_Name WHERE (Date between ? and ?)  ";
       
       pst = conn.prepareStatement(sql);
//just define it as
       pst.setString(1,((JTextField)jDateChooser1.getDateEditor().getUiComponent()).getText());
      pst.setString(2,((JTextField)jDateChooser2.getDateEditor().getUiComponent()).getText());
       rs = pst.executeQuery();

       jTable1.setModel(DbUtils.resultSetToTableModel(rs));
     
        }catch(Exception e){
            JOptionPane.showMessageDialog(null, e);
           
           
        }finally{
            try{
            rs.close();
            pst.close();
        }catch (Exception e){
              JOptionPane.showMessageDialog(null, e);  
                }
    }
    }
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Help needed how to select all entries from a table between dates

merl

 Date date1 =jDateChooser1.getDate();
        Date date2 =jDateChooser2.getDate();

if(date1 .after(historyDate) && date2.before(futureDate)) {
    // In between
}
Loading...