error code to tell db does not exist

Lists: pgsql-jdbc
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
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


From: Dave Cramer <pg(at)fastcrypt(dot)com>
To: José Arthur Benetasso Villanova <jose(dot)arthur(at)gmail(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Using PreparedStatement to call a function
Date: 2006-06-14 19:21:29
Message-ID: 75DA8EE3-3772-4265-B7E8-12F44110EBFC@fastcrypt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: 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
>


From: "surabhi(dot)ahuja" <surabhi(dot)ahuja(at)iiitb(dot)ac(dot)in>
To: <pgsql-jdbc(at)postgresql(dot)org>
Subject: error code to tell db does not exist
Date: 2006-06-15 12:57:17
Message-ID: 8626C1B7EB748940BCDD7596134632BE39868C@jal.iiitb.ac.in
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

hi,
wht is the error code returned in case the database itself does not exist.

i have the link of error codes, but i am not sure which error code will mean that.
http://www.postgresql.org/docs/8.1/static/errcodes-appendix.html

thanks
regards
Surabhi Ahuja