JDBC Date conversion

Dear Tod!

We downloaded your web application framework. This is the best

framework I've ever seen. It's really great.

We've tested JATO 1.2 and 1.2.1 on JRun 3.1. It works fine.

We encountered some problems during the test of QueryModelBase. We

are using Oracle 8.1.6EE with the Oracle JDBC driver. We have added a

new field to your CustomerModel in the JATO tutorial as follows:

FIELD_SCHEMA.addFieldDescriptor(

new QueryFieldDescriptor(

FIELD_BORNDATE,

"BornDate",

"ndnwCustomers.BornDate",

java.sql.Date.class));

The insert statement generated by the getInsertSQL() method looks

like this:

INSERT INTO ndnwCustomers

(CustomerID,CompanyName,ContactName,Phone,BornDate)

VALUES ('GGY1024','Capsys Ltd.','Geiszter Gyorgy', '288-7025' , 2002-

04-05)

We could not run the generated query because we got the following

SQLException:

java.sql.SQLException: ORA-00932: inconsistent datatypes

or

java.sql.SQLException: ORA-01861: literal does not match format string

if date string is also quoted ('2002-04-05').

The JDBC driver seems not to set the JDBC default date format for the

current database session (yyyy-mm-dd : see JDBC API doc). It's a

little bit suprising! We've found the following workarrounds for

this problem:

1. Explicit date conversion with SQL function call:

to_date(`2002-04-05', `YYYY-MM-DD')

2. Set the default date format explicitly for the current session by

executing the following query:

Connection con = ....;

Statement stmt = con.createStatement();

stmt.execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD'");

Neither of this solutions are database vendor independent and neither

of this solution are currently supported by JATO!

3. Set the default date format at database level. However I'm

affraid fixing the date format at db level in an eventually

multilingual enviroment can cause unwanted side effects at other

database clients. I think the JDBC driver should work independently

on database locale settings. Am I wrong?

Do you have any better idea?

Thanks

George Geiszter

[2349 byte] By [Guest] at [2007-11-25 9:30:35]
# 1

Hi George--

Thanks very much for the compliments! It's definitely the preferred way to

get help from our team. <grin>

I think Mike has outlined the general approach we recommend for getting

around the "date problem", but I wanted to address the following comment:

> The JDBC driver seems not to set the JDBC default date format for the

> current database session (yyyy-mm-dd : see JDBC API doc). It's a

> little bit suprising!

This is not quite the JDBC driver's fault. The reason is that JATO's

QueryModelBase class is somewhat unsophisticated, in that it doesn't use

enhanced JDBC capabilities. Specifically, I mean that this class simply

generates a SQL statement itself and then submits it to the driver, rather

than using the drivers features that support more advanced updates using the

JDBC API.

It has always been our plan to enhance QueryModelBase to use these

capabilities at some point (with demand), but it is still not possible to

use these features in all cases, or with all drivers or databases. The

exsting QueryModelBase implementation represents a minimal,

guaranteed-to-work implementation, at the cost of some of these minor

issues. Thankfully, it seems to work well enough in most situations.

By the way, if you haven't signed up for the JATO Tips forum, I highly

recommend it. There were a few tips on exactly this date issue. You can

sign up for the forum at the following location:

<a href="http://groups.yahoo.com/group/iPlanet-JATO-Tips/join">http://groups.ya hoo.com/group/iPlanet-JATO-Tips/join</a>

Todd

Guest at 2007-7-1 16:37:18 > top of Java-index,Development Tools,Java Tools...