Re: setUseServerPrepare & typecasts

From: Barry Lind <blind(at)xythos(dot)com>
To: Scott Lamb <slamb(at)slamb(dot)org>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: setUseServerPrepare & typecasts
Date: 2002-11-13 23:45:01
Message-ID: 3DD2E3FD.4020607@xythos.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)postgresql(dot)org)

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Aaron Mulder 2002-11-13 23:47:28 Re: JDBC3 and DataSource
Previous Message Michael Ansley 2002-11-13 23:28:46 JDBC3 and DataSource