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:
Connection con1 = DBConnection.connect();
int index = jList1.getSelectedIndex();
String click = (jList1.getModel().getElementAt(index).toString());
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...
Is this a sql question or JDateChooser question. If the latter, are you able to get the chosen date to your sql? Is it java.util.Date or you need to format it to YYYY-MM-DD (or some other format) with SimpleDateFormat?
Well in SQL I'm not aware of a so-called IN_BETWEEN(date1, date2) function. Yet the simplest is to do something like:
select * from table where startCol >= date1 and endCol <= date2
If your date passed into sql is a string format then you can use the to_date(date1, 'yyyy-mm-dd') function. The 2nd parm is the format.
Joined: Apr 03, 2013
thanks for the help ...
i also got the sql query ..
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 + "' and approval_date Between '" + d + "' And '" + d1 + "' "
where d1 and d is
java.util.Date date= fromchooser.getDate(); //fromchooser is jdatechooser for startdate
long dateTime = date.getTime();
java.sql.Date d = new Date(dateTime);
java.util.Date date1= tochooser.getDate(); //tochooser is jdatechooser for enddate
long dateTime1 = date1.getTime();
java.sql.Date d1 = new Date(dateTime1);
Joined: Apr 03, 2013
I'm currently developing an Equipment approval System. I'm using Java and mySQL as the database. I'm getting fairly close to finishing it all I need to do is add a few analytical abilities to it and to install it on another's pc.
But one thing I'm wondering now is how will I set up the database on their computer? Will I have to actually download mySQL and set up the tables etc? I've only done brief searches .
I was hoping anyone who has had experience in doing something similar could point me in the right direction.