Using PreparedStatement to call a function

From: José Arthur Benetasso Villanova <jose(dot)arthur(at)gmail(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Using PreparedStatement to call a function
Date: 2006-06-14 19:03:58
Message-ID: 5b12ddea0606141203w5226b35al8e12acb345710b49@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Dave Cramer 2006-06-14 19:21:29 Re: Using PreparedStatement to call a function
Previous Message Heikki Linnakangas 2006-06-14 14:57:58 Re: XA Status