1 2 Previous Next 24 Replies Latest reply on May 3, 2011 6:28 AM by user1140193

    Class Cast Exception for Date Format .

    user1140193
      Hi Friends ,

      I am getting a error for casting type from Object to Date type .

      Could you please some one help me . I am using a prepared statement in OAF for inserting a data .
      All fields are inserting except Date format .

      My code in controller as follows :
      try {    String StartDate=row.getAttribute("StartDate").toString();
      // String StartDate="30-Apr-2011";
      DateFormat formatter ;
      Date StartDate1;
      formatter = new SimpleDateFormat("dd-MMM-yy");
      StartDate1 = (Date)formatter.parse(StartDate);
      //System.out.println("Today is " +date );
      pstmt.setDate(12,StartDate1);
      } catch (ParseException e)
      {System.out.println("Exception :"+e);    }



      Thanks in Advance ,

      Keerthi
        • 1. Re: Class Cast Exception for Date Format .
          ORA_AJ
          Keerthi

          Post the complete error stack that you are getting.

          Post the result of below sop also
          system.Out.Println(row.getAttribute("StartDate").toString());
          Thanks
          AJ
          • 2. Re: Class Cast Exception for Date Format .
            HaroonAfridi
            Hi Keerthi,

            check this

            OAApplicationModule am= pageContext.getApplicationModule();
            java.sql.Date StartDate = am.getOADBTransaction().getOANLSServices().stringToDate("30-Apr-2011");
            pstmt.setDate(12,StartDate);


            Haroon
            • 3. Re: Class Cast Exception for Date Format .
              user1140193
              Thanks so Much for the quick response .

              Exception Details.

              oracle.apps.fnd.framework.OAException: java.lang.ClassCastException at oracle.apps.fnd.framework.OAException.wrapperException(OAException.java:888) at oracle.apps.fnd.framework.webui.OAPageErrorHandler.prepareException(OAPageErrorHandler.java:1145) at oracle.apps.fnd.framework.webui.OAPageErrorHandler.processErrors(OAPageErrorHandler.java:1408) at oracle.apps.fnd.framework.webui.OAPageBean.processFormRequest(OAPageBean.java:2637) at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:1659) at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:497) at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:418) at OA.jspService(OA.jsp:40) at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:56) at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:317) at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:465) at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:379) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:727) at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:306) at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:767) at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:259) at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:106) at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:803) at java.lang.Thread.run(Thread.java:534) ## Detail 0 ## java.lang.ClassCastException at SONY.oracle.apps.inv.xx_slapg.webui.ServiceRequestCO.processFormRequest(ServiceRequestCO.java:153) at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequest(OAWebBeanHelper.java:799) at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processFormRequest(OAWebBeanContainerHelper.java:363) at oracle.apps.fnd.framework.webui.OAPageLayoutHelper.processFormRequest(OAPageLayoutHelper.java:1118) at oracle.apps.fnd.framework.webui.beans.layout.OAPageLayoutBean.processFormRequest(OAPageLayoutBean.java:1579) at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequestChildren(OAWebBeanHelper.java:995) at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequestChildren(OAWebBeanHelper.java:961) at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequest(OAWebBeanHelper.java:816) at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processFormRequest(OAWebBeanContainerHelper.java:363) at oracle.apps.fnd.framework.webui.beans.form.OAFormBean.processFormRequest(OAFormBean.java:395) at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequestChildren(OAWebBeanHelper.java:995) at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequestChildren(OAWebBeanHelper.java:961) at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequest(OAWebBeanHelper.java:816) at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processFormRequest(OAWebBeanContainerHelper.java:363) at oracle.apps.fnd.framework.webui.beans.OABodyBean.processFormRequest(OABodyBean.java:363) at oracle.apps.fnd.framework.webui.OAPageBean.processFormRequest(OAPageBean.java:2633) at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:1659) at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:497) at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:418) at OA.jspService(OA.jsp:40) at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:56) at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:317) at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:465) at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:379) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:727) at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:306) at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:767) at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:259) at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:106) at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:803) at java.lang.Thread.run(Thread.java:534) java.lang.ClassCastException at SONY.oracle.apps.inv.xx_slapg.webui.ServiceRequestCO.processFormRequest(ServiceRequestCO.java:153) at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequest(OAWebBeanHelper.java:799) at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processFormRequest(OAWebBeanContainerHelper.java:363) at oracle.apps.fnd.framework.webui.OAPageLayoutHelper.processFormRequest(OAPageLayoutHelper.java:1118) at oracle.apps.fnd.framework.webui.beans.layout.OAPageLayoutBean.processFormRequest(OAPageLayoutBean.java:1579) at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequestChildren(OAWebBeanHelper.java:995) at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequestChildren(OAWebBeanHelper.java:961) at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequest(OAWebBeanHelper.java:816) at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processFormRequest(OAWebBeanContainerHelper.java:363) at oracle.apps.fnd.framework.webui.beans.form.OAFormBean.processFormRequest(OAFormBean.java:395) at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequestChildren(OAWebBeanHelper.java:995) at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequestChildren(OAWebBeanHelper.java:961) at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequest(OAWebBeanHelper.java:816) at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processFormRequest(OAWebBeanContainerHelper.java:363) at oracle.apps.fnd.framework.webui.beans.OABodyBean.processFormRequest(OABodyBean.java:363) at oracle.apps.fnd.framework.webui.OAPageBean.processFormRequest(OAPageBean.java:2633) at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:1659) at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:497) at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:418) at OA.jspService(OA.jsp:40) at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:56) at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:317) at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:465) at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:379) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:727) at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:306) at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:767) at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:259) at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:106) at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:803) at java.lang.Thread.run(Thread.java:534)

              Here is my code .
              ---------------------------------------------------------------------------------------
              java.util.Date StartDate=(java.util.Date)row.getAttribute("StartDate");
              ------------------------------------------------------------------------------------------------
              • 4. Re: Class Cast Exception for Date Format .
                HaroonAfridi
                Hi,

                1. use java.sql.Date or oracle.jbo.domain.Date instead of java.util.Date StartDate=(java.util.Date)row.getAttribute("StartDate");

                2. what is the type of your StartDate attribute ?

                Haroon
                • 5. Re: Class Cast Exception for Date Format .
                  ORA_AJ
                  Use below code
                  try 
                  {
                   String StartDate=row.getAttribute("StartDate").toString();
                  
                  // String StartDate="30-Apr-2011";
                  
                  DateFormat formatter ;
                  Date StartDate1;
                  
                  formatter = new SimpleDateFormat("dd-MMM-yyyy");
                  
                  StartDate1 = (Date)formatter.parse(StartDate);
                  
                  //System.out.println("Today is " +date );
                  
                  
                  pstmt.setDate(12,StartDate1);
                  }
                   catch (ParseException e)
                  {System.out.println("Exception :"+e); } 
                  if it fails, let me know exact line where it is failing and post the Detail 0 .... from error stack.

                  Thanks
                  AJ
                  • 6. Re: Class Cast Exception for Date Format .
                    HaroonAfridi
                    hi,

                    Basically its the problem of Date inheritance hierarchy, I think the attribute "StartDate" you are using is of type oracle.jbo.domain.Date and if you see the jdbc doc shipped with jdev then I think there is no child parent relationship of java.util.Date and oracle.jbo.domain.Date so that its throwing class cast exception. please check the jdbc part of jdev help docs.
                    • 7. Re: Class Cast Exception for Date Format .
                      user1140193
                      Thanks for you response Haroon,


                      I tried with you code , after executing its showing date the following format .

                      input : 2011-04-30

                      after executing this statment
                      String StartDate=row.getAttribute("StartDate").toString();
                      java.sql.Date StartDate = am.getOADBTransaction().getOANLSServices().stringToDate(StartDate);

                      output: 2035-10-02

                      The value is being increased , let me know why ?
                      Thanks .
                      • 8. Re: Class Cast Exception for Date Format .
                        user1140193
                        Thanks AJ ,

                        I am getting error as Date must be Initialized .

                        Any suggestions please .
                        • 9. Re: Class Cast Exception for Date Format .
                          user1140193
                          Attribute type is String .
                          • 10. Re: Class Cast Exception for Date Format .
                            HaroonAfridi
                            hi,
                            I am not sure why its doing so and I cant test it now cuz I dont have Jdev now, however I have faced such type of problem and that was easily solved with this coding technique, however you can see examples of Converting Date from String or String to Date in Jdev doc JDBC part. I hope you will find solution there.

                            input : 2011-04-30

                            after executing this statment
                            String StartDate=row.getAttribute("StartDate").toString();
                            java.sql.Date StartDate = am.getOADBTransaction().getOANLSServices().stringToDate(StartDate);

                            output: 2035-10-02


                            what is the type of database column, is it Date or Varchar.

                            Haroon

                            Edited by: Haroon Afridi on Apr 30, 2011 6:23 AM
                            • 11. Re: Class Cast Exception for Date Format .
                              ORA_AJ
                              user1140193 wrote:
                              Thanks AJ ,

                              I am getting error as Date must be Initialized .

                              Any suggestions please .
                              Which variable/code is giving this error. Please post the line number.

                              Thanks
                              AJ
                              • 12. Re: Class Cast Exception for Date Format .
                                ORA_AJ
                                Post the result of below sop also
                                system.Out.Println(row.getAttribute("StartDate").toString());
                                Thanks
                                AJ
                                • 13. Re: Class Cast Exception for Date Format .
                                  user1140193
                                  DataBase Column Type is "Date "
                                  • 14. Re: Class Cast Exception for Date Format .
                                    user1140193
                                    while printing is SOP its getting the correct output and data format .
                                    1 2 Previous Next