Indexed bind parameter with use of DSLContext's selectOne()

36 views
Skip to first unread message

Vijay Ganesan

unread,
Apr 7, 2014, 3:21:05 PM4/7/14
to jooq...@googlegroups.com

Consider a query as follows:
select 1 from sometable where somecolumn = ?;
Calling getBindValues() on the org.jooq.Query object constructed for this query returns 2 values - the first one being 1 and the second one being the parameterized value for 'somecolumn' corresponding to the '?'. 
This causes a problem when iterating through the bind values and invoking the setObject(int parameterIndex, Object x) of java.sql.PreparedStatement - this will cause an exception such as:
org.postgresql.util.PSQLException: The column index is out of range: 2, number of columns: 1.

Can someone suggest how to handle such a scenario? i.e. some way to ignore the constants which are not substitute-able indexed parameters.

Thanks
  

Lukas Eder

unread,
Apr 8, 2014, 5:09:57 AM4/8/14
to jooq...@googlegroups.com
Hello,

There's a known issue related to getBindValues() and inline parameters. See also this recent discussion:


Currently, you have two workarounds in your case:

1. Use a regular bind value for "SELECT 1", instead of an inlined one
2. Use the workaround discussed in the above thread:

Use Query.getParams()

... and then retain only those Params that have the inline flag set to false:

I hope this helps,
Lukas


--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vijay Ganesan

unread,
Apr 8, 2014, 3:03:03 PM4/8/14
to jooq...@googlegroups.com

The workaround using getParams() works fine. Thanks for the quick response.
Reply all
Reply to author
Forward
0 new messages