在用Java在日期选择器中选择日期之后,我已经有了这种格式dd/mm/yyyy
。但是在将其插入Oracle数据库之前,我想首先仅在存在月份和年份而不是日期时进行比较。如果已经记录了月份和年份,我不会不插入,如果不插入,我将其插入,然后将唯一的一天重置为该月的第一天,但保持月份和年份不变。我的程序只关心日期和月份,这就是为什么我想知道如何在插入之前仅比较两者。我尝试执行以下代码:
Resultset res = st.executeQuery("select count(*) as rowCont from doc_arriv where month_arv=to_char(chosen_date,'mm/YYYY');
res.next();
但这不是比较
calendar=java.util.Calendar.getInstance();
calendar.setTime(chosen_date);
//we must add 1 here beacause Calendar intialise months by zero
int month= calendar.get(Calendar.MONTH)+1;
//we get the year
int year= calendar.get(Calendar.YEAR);
String req = "SELECT count(*) from doc_arriv where
EXTRACT(month FROM month_arv) = " + month +
"and EXTRACT(year FROM month_arv)= " = year ;
Resultset res=st.executeQuery(req);
res.next();
//continue your code here you must calculate the result of the request if more than 1 you insert else you dont insert and for change the day to the first day of month you must execute the code
calendar.set(Calendar.DAY_OF_MONTH, 1);
chosen_date= calendar.getTime();
//good luck
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句