Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

198
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda