Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

202
Views
Lost in two jDateChoosers date spans

I'm lost, trying to take dates from two jDateChoosers then query derby database table "TEST5" column "DATEDATE" to list all records between these two dates out to my jTable.

 private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    // TODO add your handling code here:

    String url = "jdbc:derby://localhost:1527/test5";
    String user = "APP";
    String pass = "APP";

        Connection con = null;
        try {
            con = DriverManager.getConnection(url ,user, pass);
        } catch (SQLException ex) {
            Logger.getLogger(MainDisplay.class.getName()).log(Level.SEVERE, null, ex);
        }




        java.sql.Date dateStart = new java.sql.Date(jDateChooser2.getDate().getTime()); 
        java.sql.Date dateEnd = new java.sql.Date(jDateChooser3.getDate().getTime());   


       try (PreparedStatement st = con.prepareStatement("SELECT DateDate FROM TEST5 WHERE DateDate between ? AND ?" ); 
                    ResultSet rs = st.executeQuery()) {
                    st.setDate(1, dateStart);//set start date
                    st.setDate(2, dateEnd);//set end date
                    MainDisplay.jTable1.setModel(DbUtils.resultSetToTableModel(rs));


                    rs.close();
                    st.close();
                    con.close();


        } catch (SQLException ex) {
            Logger.getLogger(MainDisplay.class.getName()).log(Level.SEVERE, null, ex);
        }

This is my latest revision ( sorry, not sure where to post reply's yet)

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You don't set any value to dateStart >= ? AND dateEnd <= ? you have to use:

try (PreparedStatement st = con.prepareStatement("SELECT DateDate FROM TEST5 WHERE dateStart >= ? AND dateEnd <= ?");) {
    st.setDate(1, dateStart);//set start date
    st.setDate(2, dateEnd);//set end date
    ResultSet rs = st.executeQuery()
    MainDisplay.jTable1.setModel(DbUtils.resultSetToTableModel(rs));

Also, make sure that you set the correct name of your columns, DateDate, dateStart, dateEnd


Edit

If i understand, in your case your table has just one date and you want to get all the dates <= startDate and >= endDate this date, in this case you can use :

SELECT DateDate FROM TEST5 WHERE DateDate >= ? AND DateDate <= ?

This similaire to this between :

SELECT DateDate FROM TEST5 WHERE DateDate between ? AND ?
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!