i'm using jooq plain/raw sql, means i'm not using code generation or fluid dsl thingy.
the following code works:
connection connection = ...; dslcontext context = dsl.using(connection, ...); string sql = "select * mytable t (t.id = ?)"; string id = ...; // result<record> result = context.fetch(sql, id);
now let's have query multiple parameters this:
string sql = "select * mytable t (t.id = ?) " + "and (t.is_active = ?) , (t.total > ?)";
how use named parameter these types of queries? i'm thinking :
string sql = "select * mytable t (t.id = :id) " + "and (t.is_active = :is_active) , (t.total > :total)"; resultquery<record> rq = context.resultquery(sql); rq.getparam("id").setvalue(...); rq.getparam("is_active").setvalue(...); rq.getparam("total").setvalue(...); result<record> result = rq.fetch();
but above code doesn't work (for obvious reasons). in advance.
jooq doesn't support executing sql named parameters. can use jooq render named parameters if you're executing query api, such spring jdbc. more information, consider manual:
http://www.jooq.org/doc/latest/manual/sql-building/bind-values/named-parameters
Comments
Post a Comment