Re: setUseServerPrepare & typecasts - Mailing list pgsql-jdbc

From Barry Lind
Subject Re: setUseServerPrepare & typecasts
Date
Msg-id 3DD2E3FD.4020607@xythos.com
Whole thread Raw
In response to setUseServerPrepare & typecasts  (Scott Lamb <slamb@slamb.org>)
Responses Re: setUseServerPrepare & typecasts  (Aaron Mulder <ammulder@alumni.princeton.edu>)
List pgsql-jdbc
Scott,

That makes sense because null takes a different code path than a real
value.  Thanks for the test case.  I will look into this.

--Barry

Scott Lamb wrote:
> Barry Lind wrote:
>
>> Scott,
>>
>> If you use ps.setInt(1,42) does it work?  I want to isolate the
>> problem.  In just looking at the code, it seems that the setInt() and
>> setObject() methods do the same thing.
>
>
> Ahh, I'm sorry. setObject(1, new Object(42), Types.INTEGER) doesn't do
> it after all. I translated inappropriately when I was writing the email.
> setObject(1, null, Types.INTEGER) is the problem. Test function and Java
> program attached to reproduce.
>
> Scott
>
>
> ------------------------------------------------------------------------
>
> import java.sql.Connection;
> import java.sql.PreparedStatement;
> import java.sql.ResultSet;
> import java.sql.DriverManager;
> import java.sql.Types;
> import java.sql.SQLException;
> import org.postgresql.PGStatement;
>
> public class PreparedCastTest {
>     public static void main(String[] args) {
>         Connection c = null;
>         PreparedStatement ps = null;
>         ResultSet rs = null;
>         try {
>             c = DriverManager.getConnection(args[0], args[1], args[2]);
>             ps = c.prepareStatement("select foo(?)");
>             ( (PGStatement) ps ).setUseServerPrepare(true);
>             //ps.setInt(1, 42);
>             //ps.setObject(1, new Integer(42), Types.INTEGER);
>             ps.setObject(1, null, Types.INTEGER);
>             rs = ps.executeQuery();
>         } catch (Exception e) {
>             e.printStackTrace();
>             System.exit(1);
>         } finally {
>             if (rs != null) { try { rs.close(); } catch (Throwable t) {} }
>             if (ps != null) { try { ps.close(); } catch (Throwable t) {} }
>             if (c  != null) { try { c .close(); } catch (Throwable t) {} }
>         }
>     }
> }
>
>
>
> ------------------------------------------------------------------------
>
> create or replace function foo(integer) returns text as '
> declare
>     theint alias for $1;
> begin
>     return theint::text;
> end;' language 'plpgsql';
>
>
>
> ------------------------------------------------------------------------
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)



pgsql-jdbc by date:

Previous
From: Michael Ansley
Date:
Subject: JDBC3 and DataSource
Next
From: Aaron Mulder
Date:
Subject: Re: JDBC3 and DataSource