1 2 Previous Next 23 Replies Latest reply: Apr 25, 2013 8:00 PM by bigchill Go to original post RSS
      • 15. Re: Please Solve This Problem
        Timo Hahn
        ahmad,
        now that we see the stack trace (well done!) we see that hte problem is not in the part of the code you posted bit in the line
        at model.AppModuleImpl.createRow(AppModuleImpl.java:44)
        My guess is that in the createRow method one line is parsed and the attributes are set to the db table. On of these attributes is a date, which is read from the csv line as string. This string has to be converted into a date before setting it to the table attribute.
        Have you debugged this code step by step? This should show exaclt this.

        One moew thing: read the FAQ (https://forums.oracle.com/forums/help.jspa) to find out how code posted in this forum can be formatted. Formatted code allows us to better understand what's going on.
        Then post the code from the createRow method.

        Timo

        Edited by: Timo Hahn on 24.04.2013 09:37
        • 16. Re: Please Solve This Problem
          bigchill
          It could be a date format mismatch between what you upload via the csv versus what is expected.
          what do you do with this date field. is it getting saved to the db? can you print using nextline and see what date format gets printed out?
          • 17. Re: Please Solve This Problem
            amd_el
            First, I am very happy to help me and for your patience with me, and thank you very much to clarify how to develop code and I put it in my favorites list
            package model;
            
            
            import model.common.AppModule;
            import oracle.adf.model.adapter.dataformat.csv.CSVParser;
            import oracle.jbo.Row;
            import oracle.jbo.server.ApplicationModuleImpl;
            import oracle.jbo.server.ViewObjectImpl;
            // ---------------------------------------------------------------------
            // ---    File generated by Oracle ADF Business Components Design Time.
            // ---    Mon Apr 22 07:36:50 EET 2013
            // ---    Custom code may be added to this class.
            // ---    Warning: Do not modify method signatures of generated methods.
            // ---------------------------------------------------------------------
            public class AppModuleImpl extends ApplicationModuleImpl implements AppModule {
                /**
                 * This is the default constructor (do not remove).
                 */
                public AppModuleImpl() {
                }
            
                /**
                 * Container's getter for Ahmad1View1.
                 * @return Ahmad1View1
                 */
                public ViewObjectImpl getAhmad1View1() {
                    return (ViewObjectImpl)findViewObject("Ahmad1View1");
                }
                
                /**
                 * Method that creates a new row from String[] of values comging from the CSVParser.
                 * @param csvParser
                 */
                public void createRow(String[] lineValues){
                    ViewObjectImpl Ahmad1View1 = this.getAhmad1View1();
                    //skip first line
                        //skip firstLine as it has the headers in this case.
                            Row createRow = Ahmad1View1.createRow();
                            createRow.setAttribute("UsrCod", lineValues[0]);
                            createRow.setAttribute("UsrId", lineValues[1]);
                            createRow.setAttribute("PasWrd", lineValues[2]);
                            createRow.setAttribute("UsrNam", lineValues[3]);
                            createRow.setAttribute("UsrJob", lineValues[4]);
                            createRow.setAttribute("UsrDate", lineValues[5]);   //Here there is the problem this field not import into table 
                            
                            Ahmad1View1.insertRow(createRow);
                            Ahmad1View1.setCurrentRow(createRow);
                            
                            //Ahmad1View1.getDBTransaction().commit();
            
                }
            }
            Edited by: amd_el on Apr 24, 2013 2:06 AM
            • 18. Re: Please Solve This Problem
              bigchill
              Hi Ahmad

              I did this in a hurry so you may have some syntax errors and I have not tested it. So anyways this is the essence of what could be done. test and see.
              cheers



                   
                   
                   package model;


              import model.common.AppModule;
              import oracle.adf.model.adapter.dataformat.csv.CSVParser;
              import oracle.jbo.Row;
              import oracle.jbo.server.ApplicationModuleImpl;
              import oracle.jbo.server.ViewObjectImpl;
              // ---------------------------------------------------------------------
              // --- File generated by Oracle ADF Business Components Design Time.
              // --- Mon Apr 22 07:36:50 EET 2013
              // --- Custom code may be added to this class.
              // --- Warning: Do not modify method signatures of generated methods.
              // ---------------------------------------------------------------------
              public class AppModuleImpl extends ApplicationModuleImpl implements AppModule {
              /**
              * This is the default constructor (do not remove).
              */
              public AppModuleImpl() {
              }

              /**
              * Container's getter for Ahmad1View1.
              * @return Ahmad1View1
              */
              public ViewObjectImpl getAhmad1View1() {
              return (ViewObjectImpl)findViewObject("Ahmad1View1");
              }

              /**
              * Method that creates a new row from String[] of values comging from the CSVParser.
              * @param csvParser
              */
              public void createRow(String[] lineValues){
                   
                   
                   
              ViewObjectImpl Ahmad1View1 = this.getAhmad1View1();
                        

                        
                        
              //skip first line
              //skip firstLine as it has the headers in this case.
              Row createRow = Ahmad1View1.createRow();
              createRow.setAttribute("UsrCod", lineValues[0]);
              createRow.setAttribute("UsrId", lineValues[1]);
              createRow.setAttribute("PasWrd", lineValues[2]);
              createRow.setAttribute("UsrNam", lineValues[3]);
              createRow.setAttribute("UsrJob", lineValues[4]);
                                  
                                            //----------------------------------------------------mycode start
                                            try{   
                                                 DateFormat d ;
                                                 java.util.Date mydate = (java.util.Date)d.parse(String.valueOf(lineValues[5]));
                                            }
                                            catch(java.text.ParseException e){
                                            System.out.println("parse exception");
                                            }

                                            //----------------------------------------------------mycode end
                                  
              createRow.setAttribute("UsrDate", mydate); //changed this lines of yours

              Ahmad1View1.insertRow(createRow);
              Ahmad1View1.setCurrentRow(createRow);

              //Ahmad1View1.getDBTransaction().commit();

              }
              }
              • 19. Re: Please Solve This Problem
                Timo Hahn
                The line you marked as problem tess me that you try to put a string value, which you get from the lineValue, into a date type. This results in the error you see. You have to convert the string into a oracle.jbo.domain.Date type like
                    /**
                     * Method that creates a new row from String[] of values comging from the CSVParser.
                     * @param csvParser
                     */
                    public void createRow(String[] lineValues){
                        ViewObjectImpl Ahmad1View1 = this.getAhmad1View1();
                        //skip first line
                            //skip firstLine as it has the headers in this case.
                                Row createRow = Ahmad1View1.createRow();
                                createRow.setAttribute("UsrCod", lineValues[0]);
                                createRow.setAttribute("UsrId", lineValues[1]);
                                createRow.setAttribute("PasWrd", lineValues[2]);
                                createRow.setAttribute("UsrNam", lineValues[3]);
                                createRow.setAttribute("UsrJob", lineValues[4]);
                
                                // format of the string to parse
                                SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyy");
                                String d = lineValues[5];
                                Date date = null;
                                oracle.jbo.domain.Date od;
                                try {
                                  //create a java.util.Data 
                                  date = dateFormat.parse(d);
                                  // convert to oracle.jbo.domain.Date
                                  od = new oracle.jbo.domain.Date(date.getTime());
                                } catch (ParseException e) {
                                   e.printStackTrace();
                                } catch (SQLException e2) {
                                   e2.printStackTrace();
                                }
                                createRow.setAttribute("UsrDate", od);
                 
                                Ahmad1View1.insertRow(createRow);
                                Ahmad1View1.setCurrentRow(createRow);
                                
                                //Ahmad1View1.getDBTransaction().commit(); 
                    }
                Timo
                • 20. Re: Please Solve This Problem
                  amd_el
                  Sorry For Late I,M Trying
                  • 21. Re: Please Solve This Problem
                    amd_el
                    giving me two syntax errors
                    package model;
                    
                    
                    import java.sql.Date;
                    import java.sql.SQLException;
                    
                    import java.text.DateFormat;
                    
                    import java.text.ParseException;
                    import java.text.SimpleDateFormat;
                    
                    import model.common.AppModule;
                    import oracle.adf.model.adapter.dataformat.csv.CSVParser;
                    import oracle.jbo.Row;
                    import oracle.jbo.server.ApplicationModuleImpl;
                    import oracle.jbo.server.ViewObjectImpl;
                    //import oracle.jbo.domain.Date;
                    // ---------------------------------------------------------------------
                    // ---    File generated by Oracle ADF Business Components Design Time.
                    // ---    Mon Apr 22 07:36:50 EET 2013
                    // ---    Custom code may be added to this class.
                    // ---    Warning: Do not modify method signatures of generated methods.
                    // ---------------------------------------------------------------------
                    public class AppModuleImpl extends ApplicationModuleImpl implements AppModule {
                        /**
                         * This is the default constructor (do not remove).
                         */
                        public AppModuleImpl() {
                        }
                    
                        /**
                         * Container's getter for Ahmad1View1.
                         * @return Ahmad1View1
                         */
                        public ViewObjectImpl getAhmad1View1() {
                            return (ViewObjectImpl)findViewObject("Ahmad1View1");
                        }
                        
                        /**
                         * Method that creates a new row from String[] of values comging from the CSVParser.
                         * @param csvParser
                         */
                        public void createRow(String[] lineValues){
                            ViewObjectImpl Ahmad1View1 = this.getAhmad1View1();
                            //skip first line
                                //skip firstLine as it has the headers in this case.
                                    Row createRow = Ahmad1View1.createRow();
                                    createRow.setAttribute("UsrCod", lineValues[0]);
                                    createRow.setAttribute("UsrId", lineValues[1]);
                                    createRow.setAttribute("PasWrd", lineValues[2]);
                                    createRow.setAttribute("UsrNam", lineValues[3]);
                                    createRow.setAttribute("UsrJob", lineValues[4]);
                                    
                            // format of the string to parse
                                            SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
                                            String d = lineValues[5];
                                            Date date = null;
                                            oracle.jbo.domain.Date od;
                                            try {
                                              //create a java.util.Data 
                                              date = dateFormat.parse(d);                  //Error(61,50):  incompatible types
                                              // convert to oracle.jbo.domain.Date
                                              od = new oracle.jbo.domain.Date(date.getTime());
                                            } catch (ParseException e) {
                                               e.printStackTrace();
                                            } catch (SQLException e2) {
                                               e2.printStackTrace();
                                            }
                                            createRow.setAttribute("UsrDate", od);   //Error(69,59):  variable od might not have been initialized
                                        
                                    Ahmad1View1.insertRow(createRow);
                                    Ahmad1View1.setCurrentRow(createRow);
                                    
                                    //Ahmad1View1.getDBTransaction().commit();
                    
                        }
                    }
                    according to error 1 i cast it so it become
                    date = (Date)dateFormat.parse(d);
                    and error2 it become
                    oracle.jbo.domain.Date od=null;
                    and when i run and import give me error is
                    java.util.Date cannot be cast to java.sql.Date
                    • 22. Re: Please Solve This Problem
                      amd_el
                      and according to this code it give me 1 error is Error(64,43): cannot find variable mydate
                             //----------------------------------------------------mycode start
                              try{ 
                              DateFormat d ;
                              java.util.Date mydate = (java.util.Date)d.parse(String.valueOf(lineValues[5]));
                              }
                              catch(java.text.ParseException e){
                              System.out.println("parse exception");
                              }
                      
                              //----------------------------------------------------mycode end
                              createRow.setAttribute("UsrDate", mydate);          //Error(64,43):  cannot find variable mydate
                              Ahmad1View1.insertRow(createRow);
                              Ahmad1View1.setCurrentRow(createRow);
                       
                      • 23. Re: Please Solve This Problem
                        bigchill
                        I just moved the try catch blocks to make the variable more visible;



                        ViewObjectImpl Ahmad1View1 = this.getAhmad1View1();





                        //----------------------------------------------------mycode start
                        try{

                        //skip first line
                        //skip firstLine as it has the headers in this case.
                        Row createRow = Ahmad1View1.createRow();
                        createRow.setAttribute("UsrCod", lineValues[0]);
                        createRow.setAttribute("UsrId", lineValues[1]);
                        createRow.setAttribute("PasWrd", lineValues[2]);
                        createRow.setAttribute("UsrNam", lineValues[3]);
                        createRow.setAttribute("UsrJob", lineValues[4]);


                        DateFormat d ;
                        java.util.Date mydate = (java.util.Date)d.parse(String.valueOf(lineValues[5]));


                        createRow.setAttribute("UsrDate", mydate); //changed this lines of yours


                        Ahmad1View1.insertRow(createRow);
                        Ahmad1View1.setCurrentRow(createRow);

                        }
                        catch(java.text.ParseException e){
                        System.out.println("parse exception");
                        }

                        //----------------------------------------------------mycode end



                        //Ahmad1View1.getDBTransaction().commit();


                        }
                        }
                        1 2 Previous Next