-
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!
-
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.
-
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.
-
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.
-
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?
-
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...
-
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.
-
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...