ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Date returns null

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Date returns null

    Hello friends,
    I am having a slight problem firing queries to an AS400 table containing a date field. Now all I am doing is

    rs.executeQuery(Select avbirthdt from AW@lib2.aw@P333 where avfname='john' and avlname='smith');

    Now the resultset is retrieved this way

    if(rs.next())
    System.out.println(rs.getString(1));

    And it prinnts 'null', whereas the table has the value 10/08/1927 stored in it.

    Also, this seems to work for certain people. But for the major chunk it doesnt. Any ideas?

    Thanks,
    Ashwin

  • #2
    Re: Date returns null

    if it helps the date format looks to be in *USA not *ISO is there a way in JAVA/SQL to indicate the date type????


    Welcome to code400
    jamie
    All my answers were extracted from the "Big Dummy's Guide to the As400"
    and I take no responsibility for any of them.

    www.code400.com

    Comment


    • #3
      Re: Date returns null

      I know that we have had this conversation before but is it even possible to store a date of 10/08/1927 in a date fields defined as *USA?

      I thought that date fields define as *ISO were the only date fields capable of holding a date less than 1/1/1940.

      Is it possible that John Smit exists in your database multiple times?

      Try changing your if statement to a while loop and retest.

      PHP Code:
      while(rs.next()){
        
      System.out.println(rs.getString(1));

      Predictions are usually difficult, especially about the future. ~Yogi Berra

      Vertical Software Systems
      VSS.biz

      Comment


      • #4
        Re: Date returns null

        i tested it and yes you can

        dds
        PHP Code:
          *     outqueue file                                       
         A          R DATER                                         
         A            DATE            L         DATFMT
        (*USA)        
         
        A          K DATE 
        Attached Files
        All my answers were extracted from the "Big Dummy's Guide to the As400"
        and I take no responsibility for any of them.

        www.code400.com

        Comment


        • #5
          Re: Date returns null

          Fine!!!!!!!!


          Well the getString() method returns 'null when a 'null value is present.

          Change your code to use a while loop instead of an if and double check your database to see if more than one John Smith exists.

          PLease forgive me ignorance as I no longer have access to an System I.
          Predictions are usually difficult, especially about the future. ~Yogi Berra

          Vertical Software Systems
          VSS.biz

          Comment


          • #6
            Re: Date returns null

            I would think that sometimes thats a good thing

            I didnt know myself till I tested it...


            Hope your new position is treating you well.

            jamie
            All my answers were extracted from the "Big Dummy's Guide to the As400"
            and I take no responsibility for any of them.

            www.code400.com

            Comment


            • #7
              Re: Date returns null

              What is the field type and format of avbirthdt on the iSeries ? Formats *MDY, *DMY, *JUL, etc support only 1940-2039, but the database won't allow an invalid date anyway. However, it may be the Java code is casting it incorrectly, or you are not retrieving any data. Is "john" and "smith" in lowercase ?

              Comment


              • #8
                Re: Date returns null

                Sorry guys,

                the date I put was misleading. As to what I see the format it !SO in iSeries and the date is in this format 1927-10-08 yyyy-mm-dd.

                The problem seemed like one about date formats. I was looking up stuff about USA and ISO. Now reading the date from the table(for the ones it works) yields the date in USA format i.e. 10/08/1927 which is mm/dd/yyyy.

                In any case, I couldnt solve the problem. Just made the field numeric and got it to work. Pretty odd though!

                Thanks everybody,
                Ashwin

                Comment

                Working...
                X