Results 1 to 8 of 8
  1. #1
    chaudhas is offline Member
    Join Date
    Jun 2010
    Posts
    6
    Rep Power
    0

    Default Date format exception

    Hi,

    I have an application wherein i am fetching data from the database to create a report in java. I have used following code to display current year at the heading of the report : -

    private String getColumnHeading(TextFormatter text, String heading, CurrentSettingsDTO dto, Locale locale, Map varHeadingMap) {
    if ((heading == null) || (heading.length() == 0)) {
    return "";
    } else if (heading.startsWith("@YEARSELECTION_CURR@")) {
    return String.valueOf(dto.getYear());
    } else if (heading.startsWith("@YEARSELECTION_PREV@")) {
    return this.getPrevYear(dto);
    }
    else {
    return text.format(heading);
    }
    }


    private String getPrevYear(CurrentSettingsDTO dto)
    {
    String selYear = dto.getYear();
    int prevYr=Integer.parseInt(selYear)-1;
    return String.valueOf(prevYr);
    }
    @YEARSELECTION_CURR@ and @YEARSELECTION_PREV@ are the variables which will be replaced by current year and prev year.

    Getter and setter methods are defined as follows ;-
    public String getYear() {
    return this.selectedYear;
    }

    public void setYear(String selYear) {
    this.selectedYear = selYear;
    }

    the selected year value will fetch data from the database. Somehow when i try to run the application it works fine for year 2009 but fails for 2010 and gives below exception :-

    getting results : ORA-01840: input value not long enough for date format

    Can you please help how can i set the format for the year?

    Many thanks!

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,442
    Rep Power
    18

    Default

    So, where is that Oracle exception coming from?
    It's not in this code, since there is no SQL in here...and it's your SQL that's throwing the problem.

  3. #3
    chaudhas is offline Member
    Join Date
    Jun 2010
    Posts
    6
    Rep Power
    0

    Default

    Hello,

    After debugging the code i know where the exception is coming from.
    I am trying to get current year, current year-1 and current year -2 in a combobox designed through a grid -

    public void buildSelectTCYearFilterGrid (TextFormatter text, CurrentSettingsDTO dto, Grid grid)
    throws PersistenceException, RemoteException
    {

    try {

    Map map = this.getYearList();
    logger.debug("getYearList map::"+map);
    Iterator iter = map.keySet().iterator();
    int row = 0;
    grid.setCell(new Integer(0), 0, row);
    int value = 0;

    grid.setCell("Select", 1, row);
    grid.setCell(new Integer(1), 2, row);
    row++;
    while (iter.hasNext()) {
    String s = (String) iter.next();
    grid.setCell(s, 0, row);
    grid.setCell((String)map.get(s), 1, row);
    value = 0;
    if (s.equals(dto.getYear())) {
    value = 1;
    }
    grid.setCell(new Integer(value), 2, row);
    row++;
    }
    } catch (InvalidElementException e) {
    }
    }

    private Map getYearList() {
    Map yearList = new TreeMap(Collections.reverseOrder());
    try {
    Calendar c = new GregorianCalendar();
    int year = c.get(Calendar.YEAR);
    int prev2Year = year-2;
    int prevYear = year-1;

    yearList.put(new Integer(year).toString(),new Integer(year).toString());
    yearList.put(new Integer(prev2Year).toString(),new Integer(prev2Year).toString());
    yearList.put(new Integer(prevYear).toString(),new Integer(prevYear).toString());

    }

    catch(Exception ee)
    {
    logger.debug("Exception in getYearList - ViewHelper : " + ee);
    }


    Now above code creates a filter 'select year' with a combo box having default selection as label 'select' while other options as year 2010,2009 and 2008.

    Please let me know what needs to be done to get 2010 as default selection followed by 2009 and 2008.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,442
    Rep Power
    18

    Default

    First off, use code tags.

    Second, what's the stack trace, whole exception and line it happens on?

    As I said before, this is an ORA exception, so is coming from your SQL. Without knowing what you're putting into your SQL we can't really say what's going on....and there's no SQL in this code.

  5. #5
    chaudhas is offline Member
    Join Date
    Jun 2010
    Posts
    6
    Rep Power
    0

    Default

    SQL is working fine now and hence can be ignored..


    Could you please let me know how to get the current year as default selection in the code i've written in my previous comment?

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,442
    Rep Power
    18

    Default

    So this is no longer about an ORA error?

    OK, so...what is a Grid?
    Because I don't see a Grid class in the SDK...

  7. #7
    chaudhas is offline Member
    Join Date
    Jun 2010
    Posts
    6
    Rep Power
    0

    Default

    yes..no more ORA error now.

    Its a filter with label and a combobox. The code is for displaying a label 'Select' with a combobox getting elements from a map.

    getYearList() fetches the years in a list and public void buildSelectTCYearFilterGrid() method shows the layout how they should be placed.

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,442
    Rep Power
    18

    Default

    Great, but we don't know anything about Grid, so how can we say how to set something as selected on it?

    Assuming it's a JCombobox underneath then you either setSelectedIndex, or setSelectedObject...

Similar Threads

  1. julian date to full date format
    By judy318 in forum New To Java
    Replies: 7
    Last Post: 11-02-2009, 12:17 PM
  2. How to change the format of date?
    By jboy in forum New To Java
    Replies: 1
    Last Post: 09-09-2009, 01:22 PM
  3. Date Format
    By learnspring in forum New To Java
    Replies: 1
    Last Post: 11-16-2008, 05:16 PM
  4. How to format the date in particular pattern
    By JavaBean in forum Java Tip
    Replies: 0
    Last Post: 10-04-2007, 09:28 PM
  5. problems with Date format
    By tommy in forum New To Java
    Replies: 1
    Last Post: 07-25-2007, 08:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •