如何在oracle ADF中向用户添加日期添加天数

时间:2018-03-12 12:24:06

标签: java oracle oracle-adf

我想在每一行中迭代一个月 这是我的代码,当运行它时,它不会迭代几个月。

/** function receive date and integer then add the integer to the date then return the result date.
      (e.g. if you send 2013/07/13 and 5 to this function the function will return 2013/07/18 */

  public static Date addDayToOracleDate(oracle.jbo.domain.Date date, int days)
  {
    if (date != null)
    {
      Calendar c1 = Calendar.getInstance();
      c1.setTime(date.getValue());
      c1.add(Calendar.DATE, days);
      java.util.Date javaUtilDate = c1.getTime();
      long javaMilliseconds = javaUtilDate.getTime();
      java.sql.Date javaSqlDate = new java.sql.Date(javaMilliseconds);
      return new oracle.jbo.domain.Date(javaSqlDate);
    }
    return null;
  }
public void genrateActionLSNR(ActionEvent actionEvent) {

   BindingContainer bc = BindingContext.getCurrent().getCurrentBindingsEntry();
   DCIteratorBinding CEmpLoans1Iterator = (DCIteratorBinding)bc.get("CEmpLoans1Iterator");
    DCIteratorBinding CEmpLoans1DIterator = (DCIteratorBinding)bc.get("CEmpLoansD2Iterator");


   Number loanValue = (Number)CEmpLoans1Iterator.getCurrentRow().getAttribute("LoanValue");
   Number noOfMonths = (Number)CEmpLoans1Iterator.getCurrentRow().getAttribute("NoOfMonths");
   Date firstInstallmentDate = (Date)CEmpLoans1Iterator.getCurrentRow().getAttribute("FirstInstallmentDate");

   Number result = (Number)loanValue.div(noOfMonths);
    Date hh = firstInstallmentDate;
   for(int i=0; i<noOfMonths.getValue();i++){
       addDayToOracleDate(hh, 30);
       bc.getOperationBinding("CreateInsert1").execute();

           CEmpLoans1DIterator.getCurrentRow().setAttribute("InstallmentVal", result);
       CEmpLoans1DIterator.getCurrentRow().setAttribute("LoansMonths", hh);
       System.out.println(hh);

       //bc.getOperationBinding("Commit").execute();
   }

2 个答案:

答案 0 :(得分:0)

您假设每个月都是30天,这显然是错误的。如果您想在该日期中添加一个月,请尝试c1.add(Calendar.MONTH, 1);

答案 1 :(得分:0)

如何在Application Module中创建新方法 并使用PreparedStatement

执行类似以下SQL语句的操作
SELECT SYSDATE +:NO_OF_DAYS FROM DUAL;

将sysdate和dual替换为您的列和表