Unix Technical Forum

Jdbc : DateStyle problem

This is a discussion on Jdbc : DateStyle problem within the pgsql Interfaces jdbc forums, part of the PostgreSQL category; --> Hi, I have a weird problem with jdbc PostGreSql driver 3 (postgresql-8.2-505.jdbc3.jar) and the DateStyle parameter on a database. ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Interfaces jdbc

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-16-2008, 12:54 AM
Laurent LS. Savary
 
Posts: n/a
Default Jdbc : DateStyle problem

Hi,

I have a weird problem with jdbc PostGreSql driver 3
(postgresql-8.2-505.jdbc3.jar) and the DateStyle parameter on a
database.

If I set the following value by psql (ALTER DATABASE "myDatabase" SET
DateStyle =ISO,European), the style of date is correctly modified on the
database, even if i reconnect pgAdmin by example.
The request "show DateStyle" gives me a correct result : ISO, DMY

But, if i launch the same request by the jdbc driver (I work with
Eclipse and Sql Explorer plugins), i obtain the following result :
ISO,MDY.
Then, if i run a request, by jdbc, like : select * from table where
table.datefield = '15/01/2007' i have no result because postgresql wants
a MDY (01/15/2007) date. The same request, launched by psql, gives me
correct results.

The only way that i find is to run firstly (SET DATESTYLE TO
ISO,European on my jdbc session and then "show DateStyle" gives me :
ISO, DMY.
But, if i close my jdbc session, i lost my datestyle and "show
datestyle" returns ISO,DMY.
It's normal because the modification is set on the session only.
An another workaround is to set the DateStyle on the postgresql.conf but
all databases are impacted... Not really good.

But,why the modification of the datestyle, set by psql (alter
database....), on my database is not effective on a jdbc session?

Thanks in advance,

Regards.

Laurent Savary
SA MEDIAL
Lyon - France

---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-16-2008, 12:54 AM
Achilleas Mantzios
 
Posts: n/a
Default Re: Jdbc : DateStyle problem

Στις *αρασκευή 07 Σεπτ*μβριος 2007 11:05, ο/η Laurent LS. Savary *γραψε:
> Hi,
>
> I have a weird problem with jdbc PostGreSql driver 3

[snip]

Since you are working with java it is useless to try to format/parse
dates/timestamps with DateStyle.
Setting DateStyle is great maybe for dba scripts/reports/etc..
but for your case, just use java.text.SimpleDateFormat for both
parsing/printing.

--
Achilleas Mantzios

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-16-2008, 12:54 AM
Oliver Jowett
 
Posts: n/a
Default Re: Jdbc : DateStyle problem

Laurent LS. Savary wrote:

> But,why the modification of the datestyle, set by psql (alter
> database....), on my database is not effective on a jdbc session?


The JDBC driver resets DateStyle to a known value on each connection so
that it knows how to correctly format date values sent to the backend,
and correctly parse date values returned by the backend.

Really you should be using the JDBC methods that deal in terms of
java.sql.Date if you are manipulating dates (i.e.
PreparedStatement.setDate(), ResultSet.getDate() and so on). The driver
will then correctly handle the date value interpretation for you.

-O

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 01:08 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com