Subject | Re: [Firebird-Java] Select with constant value |
---|---|
Author | Roman Rokytskyy |
Post date | 2005-03-04T20:01:07Z |
> Now, I'm preparing this sort of query directly appending the constantYou're loosing it by calling conn.prepareStatement(String). In general each
> value to the sql string. So it looks like:
>
> int const;
>
> String str = "SELECT FIELD1, " + const + " AS CONST, FIELD2 ";
> str += "FROM TABLE1 ";
> str += "WHERE FIELD1 = ?";
>
> pst = conn.prepareStatement(str);
> pst.setInt(1, val);
> pst.execute();
>
> Am I loosing the prepared statement's befenefits in this situation? The
> const value will change in every new query.
call to Connection.prepareStatement(String) tells server to compile new
statement. However, some connection pools (including JayBird
FBWrappingDataSource) still cache prepared statements by comparing the SQL
being prepared. By appending some changing value you loose this feature too.
> The same question arises related to the "SELECT FIRST x SKIP y" clause.This should work without any problems, i.e. SELECT FIRST ? SKIP ? * FROM
> In my application I use the same way, appending to the query string the
> desired constant values, to make that kind of queries.
myTable ORDER BY myCol.
Roman