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 "Bondre, Prathit" <pb...@chdist.com> on 2006/01/26 17:41:12 UTC

iBatis Subquery and Date error

I currently have a query defined in my XML as follows

 

<statement id="insertQuery" parameterClass="java.util.Map"
remapResults="true">

            Insert into table 

            Select

                        Address,

                        City,

                        Zip,

                        $name$ as name,

                        $effDate$ as date

            From

                        Table

            Where

                        Id = #id#

</statement>

 

When I call it using the HashMap and set the effDate with java.sql.Date
object it throws an exception

That the  value is not compatible with the datatype of the target which
is defined in the database as a Date field.

Also based on the documentation I also tried to pass in a java.util.Date
instead of the java.sql.Date and it got an error 

"An unexpected token was found" and it seemed like it was passing in the
String version of the Date field which included the timestamp in the
data and it was choking on the : in the timestamp.

 

How should I be passing the effDate to this query?

 

So far I had

HashMap params = new HashMap();

Params.put("name","Value")

Params.put ("effDate",effDate) // effDate is an instance of
java.sql.Date . Also tried with java.util.Date.

 

What am I doing wrong?

 

Any help will be appreciated.

 

Thanks,

Prathit Bondre

 


Re: iBatis Subquery and Date error

Posted by Nathan Maves <Na...@Sun.COM>.
haha that is what I meant to say.  Sorry about the confusion.

busy day here at the office.
On Jan 26, 2006, at 3:03 PM, Michael Campbell wrote:

> Nathan Maves <Na...@Sun.COM> writes:
>
>> Stick with java.sql.Date.  Try never to use java.util.Date.
>
> Why?
>
> The Ibatis datamapper doc (2.0, page 31) says:
>
> "The use of java.sql.date types is discouraged. It is a best practice
> to use java.util.Date instead."
>
> I'm tending to go with the author of the framework here...
>


Re: iBatis Subquery and Date error

Posted by Michael Campbell <mi...@gmail.com>.
Nathan Maves <Na...@Sun.COM> writes:

> Stick with java.sql.Date.  Try never to use java.util.Date.

Why?

The Ibatis datamapper doc (2.0, page 31) says:  

"The use of java.sql.date types is discouraged. It is a best practice
to use java.util.Date instead."

I'm tending to go with the author of the framework here...


Re: iBatis Subquery and Date error

Posted by Nathan Maves <Na...@Sun.COM>.
Here are a few things to do that will not solve your problem but will  
help clean it up.

1. Use the <insert> instead of <statement>
2. Don't specify "remapResults" because you dont have any :)  This  
option is not available in an <insert> see item #1

To fix your problem....

use #name# and #effDate#

you are also missing the id parameter in the HashMap


Stick with java.sql.Date.  Try never to use java.util.Date.

Nathan




On Jan 26, 2006, at 9:41 AM, Bondre, Prathit wrote:

> I currently have a query defined in my XML as follows
>
>
>
> <statement id=”insertQuery” parameterClass=”java.util.Map”  
> remapResults=”true”>
>
>             Insert into table
>
>             Select
>
>                         Address,
>
>                         City,
>
>                         Zip,
>
>                         $name$ as name,
>
>                         $effDate$ as date
>
>             From
>
>                         Table
>
>             Where
>
>                         Id = #id#
>
> </statement>
>
>
>
> When I call it using the HashMap and set the effDate with  
> java.sql.Date object it throws an exception
>
> That the  value is not compatible with the datatype of the target  
> which is defined in the database as a Date field.
>
> Also based on the documentation I also tried to pass in a  
> java.util.Date instead of the java.sql.Date and it got an error
>
> “An unexpected token was found” and it seemed like it was passing  
> in the String version of the Date field which included the  
> timestamp in the data and it was choking on the : in the timestamp.
>
>
>
> How should I be passing the effDate to this query?
>
>
>
> So far I had
>
> HashMap params = new HashMap();
>
> Params.put(“name”,”Value”)
>
> Params.put (“effDate”,effDate) // effDate is an instance of  
> java.sql.Date . Also tried with java.util.Date.
>
>
>
> What am I doing wrong?
>
>
>
> Any help will be appreciated.
>
>
>
> Thanks,
>
> Prathit Bondre
>
>
>
>


Re: iBatis Subquery and Date error

Posted by Jeff Butler <je...@gmail.com>.
Yes, iBATIS will do a toString() on the effDate in this case - because it is
not a parameter for the SQL, rather it is a substitution value.

The solution is to put effDate into the map as a String in the format that
your database understands.  In other words, you'll have to format the date
yourself.

Jeff Butler


On 1/26/06, Bondre, Prathit <pb...@chdist.com> wrote:
>
>  I currently have a query defined in my XML as follows
>
>
>
> <statement id="insertQuery" parameterClass="java.util.Map"
> remapResults="true">
>
>             Insert into table
>
>             Select
>
>                         Address,
>
>                         City,
>
>                         Zip,
>
>                         $name$ as name,
>
>                         $effDate$ as date
>
>             From
>
>                         Table
>
>             Where
>
>                         Id = #id#
>
> </statement>
>
>
>
> When I call it using the HashMap and set the effDate with java.sql.Dateobject it throws an exception
>
> That the  value is not compatible with the datatype of the target which is
> defined in the database as a Date field.
>
> Also based on the documentation I also tried to pass in a java.util.Dateinstead of the
> java.sql.Date and it got an error
>
> "An unexpected token was found" and it seemed like it was passing in the
> String version of the Date field which included the timestamp in the data
> and it was choking on the : in the timestamp.
>
>
>
> How should I be passing the effDate to this query?
>
>
>
> So far I had
>
> HashMap params = new HashMap();
>
> Params.put("name","Value")
>
> Params.put ("effDate",effDate) // effDate is an instance of java.sql.Date. Also tried with
> java.util.Date.
>
>
>
> What am I doing wrong?
>
>
>
> Any help will be appreciated.
>
>
>
> Thanks,
>
> Prathit Bondre
>
>
>