0

I am trying to solve a problem of my code. In the following code, it contains JComboBox which have a list of month. When I click on January, I want to show all the details of that month.

private void jComboBox1_MonthsActionPerformed(java.awt.event.ActionEvent evt) {   
  String selection = (String)jComboBox1_Months.getSelectedItem();
     if(selection.equals("January")){
        try{

          String sql = "select * from booking where Date = ??/01/??"; //problem
          pst = conn.prepareStatement(sql);
          rs = pst.executeQuery();
          viewBookingTable.setModel(DbUtils.resultSetToTableModel(rs));
          } catch(Exception e){

          }     
     }
}  

The format for the Date is 12/01/16 in the Database with type CHAR.
Please help. Thank you very much in advance.

0

3 Answers 3

1

Even though I suggest revisiting your aprroach and favor the usage of the java.sql.Date type, you can select the desired rows using a LIKE predicate:

String sql = "SELECT * FROM booking WHERE Date LIKE '%/01/%'";
Sign up to request clarification or add additional context in comments.

Comments

0

Yo could do that:

String sql = "select * from booking where SUBSTR(Date,4,2) = "01";

Comments

0
int index = jComboBox1_Months.getSelectedIndex() + 1;
String sql = "SELECT * FROM `booking` WHERE `date` like '%?%';
pst = conn.prepareStatement(sql);
pst.setObject(1, index);
...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.