You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Mayeul MARGUET <mm...@aneo.fr> on 2006/06/05 16:30:29 UTC

Using non-default timezones

Subject: Using non-default timezones

Hi!

I'm using iBatis to store and fetch dates and hourly timestamps in and
from an Oracle database.
An sql-map fragment is given below as example.

I need these dates and timestamps to be stored as their UTC values, but
when I insert a date using an iBatis insert statement, the value is
stored using my default timezone (ie: for a GMT-1 default timezone,
01/01/2006 00:00:00 UTC is stored as 12/31/2005 or 12/31/2005 23:00:00).
This is a logical default behaviour, but still not the one I need.


I did find a few sql-map examples around the net suggesting there was an
easy way to handle timezones, but failed both to understand how to use
them and to find a documentation on the subject of dates and timezones
with iBatis.


Is there an official way to do it, which would save me the hassle of
modifying my default timezone or storing my dates and timestamps as
text?
Could you point me to a documentation covering the subject?

Or do you think I am missing something and should investigate towards
some Oracle configuration I'm not aware of?

Thanks!


Here is my sql-map example, kinda straightforward:

	<resultMap id="NameTimestampDate.map"
class="NameTimestampDate.class">
		<result property="name" column="NAME" />
		<result property="timestamp" column="MY_TIMESTAMP" />
		<result property="date" column="MY_DATE" />
	</resultMap>

	<select id="getNameTimestampDateByName"
		resultMap="NameTimestampDate.map"
		parameterClass="java.lang.String">

		<![CDATA[
		SELECT * FROM TEST_TIMESTAMPS
			WHERE NAME = #name#
		]]>		
	</select>

	<insert id="insertNameTimestampDate"
		parameterClass="NameTimestampDate.class">

		<![CDATA[
		INSERT INTO TEST_TIMESTAMPS (NAME, MY_TIMESTAMP,
MY_DATE)
			VALUES (#name#, #timestamp#, #date#)
		]]>		
	</insert>

--
Mayeul


Re: Using non-default timezones

Posted by Brandon Goodin <br...@gmail.com>.
iBATIS does not mess with your date values in any way that I am aware
of. What you pass in is what gets stored. If iBATIS is changing your
date values upon insertion then this would be a bug. So, it is your
responsibility to set the Date value on your object correctly prior to
asking iBATIS to insert the information into your database. As stated
by Graeme, you will need to use the Calendar object to accomplish
this.

Brandon Goodin



On 6/5/06, Mayeul MARGUET <mm...@aneo.fr> wrote:
> Subject: Using non-default timezones
>
> Hi!
>
> I'm using iBatis to store and fetch dates and hourly timestamps in and
> from an Oracle database.
> An sql-map fragment is given below as example.
>
> I need these dates and timestamps to be stored as their UTC values, but
> when I insert a date using an iBatis insert statement, the value is
> stored using my default timezone (ie: for a GMT-1 default timezone,
> 01/01/2006 00:00:00 UTC is stored as 12/31/2005 or 12/31/2005 23:00:00).
> This is a logical default behaviour, but still not the one I need.
>
>
> I did find a few sql-map examples around the net suggesting there was an
> easy way to handle timezones, but failed both to understand how to use
> them and to find a documentation on the subject of dates and timezones
> with iBatis.
>
>
> Is there an official way to do it, which would save me the hassle of
> modifying my default timezone or storing my dates and timestamps as
> text?
> Could you point me to a documentation covering the subject?
>
> Or do you think I am missing something and should investigate towards
> some Oracle configuration I'm not aware of?
>
> Thanks!
>
>
> Here is my sql-map example, kinda straightforward:
>
>         <resultMap id="NameTimestampDate.map"
> class="NameTimestampDate.class">
>                 <result property="name" column="NAME" />
>                 <result property="timestamp" column="MY_TIMESTAMP" />
>                 <result property="date" column="MY_DATE" />
>         </resultMap>
>
>         <select id="getNameTimestampDateByName"
>                 resultMap="NameTimestampDate.map"
>                 parameterClass="java.lang.String">
>
>                 <![CDATA[
>                 SELECT * FROM TEST_TIMESTAMPS
>                         WHERE NAME = #name#
>                 ]]>
>         </select>
>
>         <insert id="insertNameTimestampDate"
>                 parameterClass="NameTimestampDate.class">
>
>                 <![CDATA[
>                 INSERT INTO TEST_TIMESTAMPS (NAME, MY_TIMESTAMP,
> MY_DATE)
>                         VALUES (#name#, #timestamp#, #date#)
>                 ]]>
>         </insert>
>
> --
> Mayeul
>
>

Re: Using non-default timezones

Posted by Graeme J Sweeney <ib...@gjsweeney.com>.
On Mon, 5 Jun 2006, Mayeul MARGUET wrote:

> Is there an official way to do it, which would save me the hassle of
> modifying my default timezone or storing my dates and timestamps as
> text?

Create a TimeZone for GMT and use that to create a Calendar instance.
That should help with the insertions.

> Could you point me to a documentation covering the subject?

java.util.Calendar in the API docs.

-- 
Graeme -