Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

java.sql version dependencies for date handling?

3 views
Skip to first unread message

Jennifer Amon

unread,
Dec 6, 2002, 10:29:47 AM12/6/02
to
I have a program that works great on one machine and doesn't work on
another machine. The problem is with dealing with dates. I think it
might be a java.sql issue. I'll take any help/advice I can get.

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?

John Rogers

unread,
Dec 6, 2002, 1:56:06 PM12/6/02
to Jennifer Amon


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

Jennifer Amon

unread,
Dec 6, 2002, 11:30:13 PM12/6/02
to
I'm sorry, but I don't understand what that means in the context of my problem?

John Rogers <jr...@mindspring.com> wrote in message news:<3DF0F2C6...@mindspring.com>...

Jennifer Amon

unread,
Dec 9, 2002, 9:06:34 AM12/9/02
to
In the latest version of my code, I eliminated the need for the
SimpleDateFormat, and hence the applyPattern, by getting a date field
directly into a date variable using getDate() rather than getString().

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

bung ho

unread,
Dec 9, 2002, 6:30:47 PM12/9/02
to
ja...@apk.net (Jennifer Amon) wrote in message news:<7bd10c00.02120...@posting.google.com>...

i'm confused. what is the source db that you're using (the one that
the ResultSet "rs3" is coming from)?

0 new messages