Informix

 View Only
  • 1.  Migration from Informix 9 to Informix 15, JDBC Problem with float in prepared statements

    Posted 16 hours ago
    Why I don't know but does

    select 2.0::FLOAT * ? from dsfco
    select (2.0::FLOAT * ? )::FLOAT from dsfco

    work as expexted

    On 2/26/2025 8:48 AM, Andreas Ittgenshorst via IBM TechXchange Community wrote:
    0100019542bafaa4-b89ad4c7-de32-47aa-8246-08100675fa82-000000@email.amazonses.com">
    Hi, we are currently using an Informix 9 server and would like to switch to Informix 15. We have a problem when using prepared statements with... -posted to the "Informix" group


  • 2.  RE: Migration from Informix 9 to Informix 15, JDBC Problem with float in prepared statements

    Posted 14 hours ago

    Hi Paul,

    thanks for your reply. Yes, that works. Expected result and on the server side the host variable is type float.

    select 2::FLOAT * ? from dsfco
    result: 0.0074800001457333565

    select (2::FLOAT * ?)::FLOAT from dsfco
    result: 0.0074800001457333565


    Server side Host Variables
    Position Type    Value
    0        float     0.0037400000728667

    I am wondering why "select 2 * ? from dsfco" with the following code leads to a host variable of type integer although I defined it as float.

    String query = "select 2 * ? as result from dsfco";
    float val = 0.00374f;
    stmt = conn.prepareStatement(query);
    stmt.setFloat(1, val);
    rs = stmt.executeQuery();

    Could it be a problem/bug in the jdbc-15.0.0.0.jar driver?
    Or does jdbc send it correctly and the database server converts it afterwards from "float 0.00374" to "int 0"?

    BR,
    Andreas



    ------------------------------
    Andreas Ittgenshorst
    ------------------------------



  • 3.  RE: Migration from Informix 9 to Informix 15, JDBC Problem with float in prepared statements

    Posted 12 hours ago

    Andreas:

    The result of the calculation "2 * ?" is being interpreted as type INTEGER because the "2" is an INTEGER as it has not decimal point. You might try "2.0 * ?".

    Also note that it is a good practice when including calculations in the projection clause of a SELECT to surround the formula with parenthesis to prevent operators from being misinterpreted. In this case that did not happen, but remember that an asterisk (*) has a special meaning in the projection clause! So next time do:

    SELECT (2 * ?) FROM ...

    Art



    ------------------------------
    Art S. Kagel, President and Principal Consultant
    ASK Database Management Corp.
    www.askdbmgt.com
    ------------------------------