How can i get value from 2 JDateChooser formatted yyyy-MM-d and put it in sql query (
String sql="select .... from ... between date1 and date2") which should search data between those dates and outputted in a JTable.
I used code but no output appeared:
try {
Connection con1 = DBConnection.connect();
int index = jList1.getSelectedIndex();
String click = (jList1.getModel().getElementAt(index).toString());
String sql = "SELECT distinctrow request.file_no , request.file_subject , request.hardware_request , approval.quantity , approval.approved_quantity FROM request INNER JOIN approval ON request.id = approval.id WHERE request.selected_department = '" + click + "' ";
PreparedStatement pst = con1.prepareStatement(sql);
ResultSet rst = pst.executeQuery();
ResultSetMetaData rsMetaData = (ResultSetMetaData) rst.getMetaData();
int cols = rsMetaData.getColumnCount();
System.out.println("database" + cols);
for (int i = 1; i < cols; i++) {
columnNames.addElement(rsMetaData.getColumnName(i));
}
System.out.println("while ke baher");
while (rst.next()) {
System.out.println("while ke ander");
Vector row = new Vector(cols);
for (int i = 1; i <= 1; i++) {
row.addElement(rst.getObject(i));
}
int ro = row.size();
System.out.println(ro + "row val");
for (int i = 1; i <= 1; i++) {
String file_no = rst.getString("file_no");
System.out.println(file_no);
String sub = rst.getString("file_subject");
System.out.println(sub);
String hard = rst.getString("hardware_request");
System.out.println(hard);
String rquan = rst.getString("quantity");
System.out.println(rquan);
String aquan = rst.getString("approved_quantity");
System.out.println(aquan);
//
DefaultTableModel model1 = (DefaultTableModel) mis_dept.getModel();
model1.addRow(new Object[]{ file_no, sub,hard,rquan, aquan});
}
}
//
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "Error in submitting data!" + ex);
}
please tell me how i use the where clause with 2 conditions as i use WHERE request.selected_department = '" + click + "' "...
and 2nd clause to search data between two dates..
any help will be apperitiated...