I connect to a database, get data, and write it to a spreadsheet using
the Jakarta POI HSSF stuff. One column is a date column. I have tried
two alternatives:
1)Getting the date as a string, from a string column in the DB,
converting to a date and putting it into the spreadsheet.
On one machine, it works fine:
Windows 2000 machine
Java 2 platform SE v1.4.1-b21
jakarta-poi-1.9.0-dev-20021107.jar
On another machine, the ResultSet.getString() gets null (same
database)
NT 4
Java 2 platform SE v1.3.0_02
jakarta-poi-1.9.0-dev-20021107.jar
2) Getting the date value as a date, from a date field in the DB,
using ResultSet.getDate().
Win2K machine - works fine.
NT 4 machine - ResultSet.getDate() returns a null date value:
Starting Program
Input Parameters:
Output file specification:
d:\wwwmoencom\wwwroot\prodinfo\Pricing.xls
Datasource: updprodinfo
Catalog: WHOLESALE
Debug turned OFF
Publist (determined by catalog): 'MF36','MF1415','MF1426'
Creating Workbook
Connecting to DB
Drop old table
Create new table
Query
launchDate: null
java.lang.NullPointerException
at java.util.Calendar.setTime(Unknown Source)
at org.apache.poi.hssf.usermodel.HSSFDateUtil.getExcelDate(HSSFDateUtil.java:99)
at org.apache.poi.hssf.usermodel.HSSFCell.setCellValue(HSSFCell.java:646)
at DBtoExcel2.addRow(DBtoExcel2.java:68)
at DBtoExcel2.main(DBtoExcel2.java:576)
Exception in thread "main"
Here's the code snippet (first version is commented out):
/*
// Deal with a date field
// Note: could have simply used getDate from resultSet
launchDateString = rs3.getString("ss_launch_date");
// now convert string to date
System.out.println("launchDateString: " + launchDateString);
try {
launchDate = sdf.parse(launchDateString);
}
catch (java.text.ParseException pe) {
System.out.println("Error: unable to parse date string - " +
launchDateString);
}
catch (NullPointerException npe) {
System.out.println("Error: null pointer exception for string:
" + launchDateString);
}
*/
// trying getDate with date field instead of getString with string
launchDate = rs3.getDate("ss_launch_date");
System.out.println("launchDate: " + launchDate);
// and assign the date value to the cell
rowdata[colnum++].setCellInfo("Date",launchDate,csdate);
Does anybody have a clue what is going on here?
Date: 2002-12-06
Cc: jr...@mindspring.com
Subject: java.text.SimpleDateFormat parse bug on NT Tomcat JDK 1.2.2
Newsgroups: comp.lang.java.databases
Hi all! The NT Tomcat JDK 1.2.2 implementation its pattern
constructor actually ignores the pattern. We need to
call applyPattern( pattern ) to get it to work.
Hope this helps...
--JR (John Rogers, jr...@mindspring.com)
--
John "JR" Rogers, programming somewhere near Seattle...
mailto:jr...@mindspring.com
John Rogers <jr...@mindspring.com> wrote in message news:<3DF0F2C6...@mindspring.com>...
Still, on one machine, I get the dates back from the query, and on
another, I get nulls - and, just for the date field. Other fields are
all okay.
This doesn't make sense to me, especially when I tried it as a plain
text field in the db with a getString(), just like the other text
fields being retrieved.
Still, any ideas would be greatly appreciated.
Thanks!!!
i'm confused. what is the source db that you're using (the one that
the ResultSet "rs3" is coming from)?