pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedUsing PreparedStatement to call a function
2+ messages / 2 participants
[nested] [flat]
* Using PreparedStatement to call a function
@ 2006-06-14 19:03 José Arthur Benetasso Villanova <jose.arthur@gmail.com>
2006-06-14 19:21 ` Re: Using PreparedStatement to call a function Dave Cramer <pg@fastcrypt.com>
0 siblings, 1 reply; 2+ messages in thread
From: José Arthur Benetasso Villanova @ 2006-06-14 19:03 UTC (permalink / raw)
To: pgsql-jdbc
HI all.
I have a function called:
dbcmp(
t varchar,
p varchar[],
c varchar[],
n INTEGER
) RETURNS SETOF dbcmp_t
...
Today, I call my function like this:
String sql = "select * from dbcmp('" + t + "','" + p + "','" + "'," + n + ")";
Statement stmt = con.createStatement(sql);
ResultSet rs = stmt.executeQuery();
...
I want to transform my code to use PreparedStatement like this:
String sql = "select * from dbcmp(?, ?, ?, ?)";
PreparedStatement ps = con.preparedStatement(sql);
ps.setString(1, t);
ps.setArray(2, p);
ps.setArray(3, c);
ps.setInt(4, n);
But I don´t know how to create an Array object to use the set.
Can anyone help me? :-)
Thanks in advance.
--
José Arthur Benetasso Villanova
ICQ 2138887
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Using PreparedStatement to call a function
2006-06-14 19:03 Using PreparedStatement to call a function José Arthur Benetasso Villanova <jose.arthur@gmail.com>
@ 2006-06-14 19:21 ` Dave Cramer <pg@fastcrypt.com>
0 siblings, 0 replies; 2+ messages in thread
From: Dave Cramer @ 2006-06-14 19:21 UTC (permalink / raw)
To: José Arthur Benetasso Villanova <jose.arthur@gmail.com>; +Cc: pgsql-jdbc
Jose,
Check the archives there are a few,
Basically you have to create a class which implements the Array
interface. Most of it can be unimplemented, except for toString which
will have to return
"{string1, string2}"
and
getBaseTypeName()
which will have to return "varchar" in the case of varchar[]
Dave
On 14-Jun-06, at 3:03 PM, José Arthur Benetasso Villanova wrote:
> HI all.
>
> I have a function called:
>
> dbcmp(
> t varchar,
> p varchar[],
> c varchar[],
> n INTEGER
> ) RETURNS SETOF dbcmp_t
> ...
>
>
> Today, I call my function like this:
>
> String sql = "select * from dbcmp('" + t + "','" + p + "','" + "',"
> + n + ")";
> Statement stmt = con.createStatement(sql);
> ResultSet rs = stmt.executeQuery();
> ...
>
> I want to transform my code to use PreparedStatement like this:
>
> String sql = "select * from dbcmp(?, ?, ?, ?)";
> PreparedStatement ps = con.preparedStatement(sql);
> ps.setString(1, t);
> ps.setArray(2, p);
> ps.setArray(3, c);
> ps.setInt(4, n);
>
> But I don´t know how to create an Array object to use the set.
>
> Can anyone help me? :-)
>
> Thanks in advance.
>
> --
> José Arthur Benetasso Villanova
> ICQ 2138887
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
> http://archives.postgresql.org
>
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2006-06-14 19:21 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-06-14 19:03 Using PreparedStatement to call a function José Arthur Benetasso Villanova <jose.arthur@gmail.com>
2006-06-14 19:21 ` Dave Cramer <pg@fastcrypt.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox