Results 1 to 8 of 8
Thread: Date format exception
- 06-24-2010, 06:43 AM #1
Member
- Join Date
- Jun 2010
- Posts
- 6
- Rep Power
- 0
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!
- 06-24-2010, 09:44 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
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.
- 06-24-2010, 01:19 PM #3
Member
- Join Date
- Jun 2010
- Posts
- 6
- Rep Power
- 0
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.
- 06-24-2010, 01:58 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
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.
- 06-25-2010, 05:09 AM #5
Member
- Join Date
- Jun 2010
- Posts
- 6
- Rep Power
- 0
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?
- 06-25-2010, 08:54 AM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
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...
- 06-25-2010, 09:08 AM #7
Member
- Join Date
- Jun 2010
- Posts
- 6
- Rep Power
- 0
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.
- 06-25-2010, 09:31 AM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Similar Threads
-
julian date to full date format
By judy318 in forum New To JavaReplies: 7Last Post: 11-02-2009, 12:17 PM -
How to change the format of date?
By jboy in forum New To JavaReplies: 1Last Post: 09-09-2009, 01:22 PM -
Date Format
By learnspring in forum New To JavaReplies: 1Last Post: 11-16-2008, 05:16 PM -
How to format the date in particular pattern
By JavaBean in forum Java TipReplies: 0Last Post: 10-04-2007, 09:28 PM -
problems with Date format
By tommy in forum New To JavaReplies: 1Last Post: 07-25-2007, 08:38 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks