Re: syntax error on escape sequences with bind variables
- From: "Sue Purkis" <suepurkis@xxxxxxxxx>
- Date: Tue, 31 May 2005 11:25:50 -0400
Lenny,
We spent some time looking at this issue. We were able to recreate your
problem using a smaller sql statement. We used
select count( * ) from datetable where fn YEAR(tran_date) >= fn YEAR({d
?})
According to the SQL Server books online, the YEAR function takes a
string argument. By using the date escape syntax above you are trying to
pass a date to the YEAR function. When we change the parameter in the YEAR
function to be a string using the syntax "select count( * ) from datetable
where fn YEAR(tran_date) >= fn YEAR(?)" and then binding the value with
setString, the query works.
Can you test this out for us to see if it addresses your issue? Is there
some particular functionality you are looking for by passing the date escape
syntax to the YEAR function?
Thanks.
Sue Purkis
DataDirect Technologies
<lpalozzi@xxxxxxxxx> wrote in message
news:1116264061.117026.71970@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Hi,
>
> I'm getting the following syntax error while preparing my statement. I
> believe the problem is caused by the use of bind variables within JDBC
> escape sequences, eg. {fn YEAR( {d ?} )}.
>
> JDBC driver is:
>
> Microsoft SQL Server 2000 Driver for JDBC
> Service Pack 3
> Version 2.2.0040
> May 2004
>
>
> Note that the Oracle JDBC drivers parse and execute this just fine. Is
> this a bug? Is there a work around?
>
> See query and stack trace below.
>
> select count( * ) from ( select count( * ) as cnt from tablename where
> {fn YEAR (tran_date)} >= {fn YEAR( {d ? } )} and {fn YEAR (tran_date)}
> <= {fn YEAR( {d ? } )} and {fn MONTH(tran_date)} >= {fn MONTH( {d ?
> } )} and {fn MONTH(tran_date)} <= {fn MONTH( {d ? } )} and {fn
> DAYOFMONTH(tran_date)} >= {fn DAYOFMONTH( {d ? } )} and {fn
> DAYOFMONTH(tran_date)} <= {fn DAYOFMONTH( {d ? } )} ) temp
>
> java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for
> JDBC]Syntax error at token ?, line 0 offset 3.
> at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown
> Source)
> at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
> at com.microsoft.jdbc.base.BaseEscapeTranslator.parseEscape(Unknown
> Source)
> at
> com.microsoft.jdbc.base.BaseEscapeTranslator.translateEscape(Unknown
> Source)
> at com.microsoft.jdbc.base.BaseSQLEscapeProcessor.visit(Unknown
> Source)
> at com.microsoft.jdbc.base.BaseSQLTreeTraverser.visit(Unknown Source)
> at
> com.microsoft.jdbc.base.BaseSQLTreePreOrderTraverser.traverse(Unknown
> Source)
> at
> com.microsoft.jdbc.base.BaseSQLTreePreOrderTraverser.traverse(Unknown
> Source)
> at
> com.microsoft.jdbc.base.BaseSQLTreePreOrderTraverser.traverse(Unknown
> Source)
> at
> com.microsoft.jdbc.base.BaseSQLEscapeProcessor.processEscapes(Unknown
> Source)
> at com.microsoft.jdbc.base.BaseSQLEscapeProcessor.visit(Unknown
> Source)
> at com.microsoft.jdbc.base.BaseSQLTreeTraverser.visit(Unknown Source)
> at
> com.microsoft.jdbc.base.BaseSQLTreePreOrderTraverser.traverse(Unknown
> Source)
> at
> com.microsoft.jdbc.base.BaseSQLTreePreOrderTraverser.traverse(Unknown
> Source)
> at
> com.microsoft.jdbc.base.BaseSQLEscapeProcessor.processEscapes(Unknown
> Source)
> at com.microsoft.jdbc.base.BaseSQL.translateEscapes(Unknown Source)
> at com.microsoft.jdbc.base.BaseSQL.processSQL(Unknown Source)
> at com.microsoft.jdbc.base.BaseSQL.<init>(Unknown Source)
> at com.microsoft.jdbc.base.BaseStatement.preProcessSQL(Unknown Source)
> at com.microsoft.jdbc.base.BasePreparedStatement.<init>(Unknown
> Source)
> at com.microsoft.jdbc.base.BaseConnection.prepareStatement(Unknown
> Source)
> at com.microsoft.jdbc.base.BaseConnection.prepareStatement(Unknown
> Source)
>
>
> Thanks,
>
> -Lenny
>
.
- References:
- syntax error on escape sequences with bind variables
- From: lpalozzi
- syntax error on escape sequences with bind variables
- Prev by Date: Re: java replication app
- Previous by thread: syntax error on escape sequences with bind variables
- Next by thread: PreparedStatement.cancel() does not work with SP3
- Index(es):
Relevant Pages
|
Loading