Menu

#142 Cannot coerce host var to type integer when trying to bind an interval literal to a prepared statement

open
nobody
None
5
2012-04-02
2012-04-02
Jira Trac
No

The following statement cannot be executed with JDBC:

{code}
Connection connection = create().getConnection();
PreparedStatement s = connection.prepareStatement(
select DATE_ADD('2010-01-01', INTERVAL ? YEAR_MONTH));

s.setString(1, +1-6);
s.executeQuery();
{code}

It can be executed without problems in CUBRID Manager. It seems that only simple interval types are supported in JDBC. The following works:

{code}
Connection connection = create().getConnection();
PreparedStatement s = connection.prepareStatement(
select DATE_ADD('2010-01-01', INTERVAL ? DAY));

s.setString(1, 1);
s.executeQuery();
{code}

And so does this:

{code}
Connection connection = create().getConnection();
PreparedStatement s = connection.prepareStatement(
select DATE_ADD('2010-01-01', INTERVAL '+1-6' YEAR_MONTH));

s.executeQuery();
{code}

Discussion

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.