From: | vorarlberger at gmail(dot)com (Vorarlberger) |
---|---|
To: | |
Subject: | [Pljava-dev] Return a Anonymous ResultSet |
Date: | 2011-09-01 09:41:18 |
Message-ID: | CALtUeZZ8RB87yre140-E_ZrcFQGqLXJVEBCa7FYq6dTo4pSGPg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pljava-dev |
Hi
In reference to this very year old thread:
http://pgfoundry.org/pipermail/pljava-dev/2005/000277.html I have a very
similar problem and I am not sure if this problem is still remaining?
What I need is to return a result set I do not know at create time. In fact
my java code is holding a HashMap<string,object> and I need to return the
map as a table.
I thought a dummy select to return thre result will do the trick (see
this pseudo code):
PreparedStatement ps = null;
String sql = "select ";
for key in keys in map loop
sql += "? as " + key + ", ";
end loop
//expecing sql as a string like "select ? as name, ? as salary, ? as
hiredate, ? as somearray"
int i =0;
for key in keys in map loop
Object o = map.getValueOf(key);
i++;
if (o instanceof Integer) {
ps.setInt(i, (Integer) o);
} elesif ( ... ) {
do for all known types
} else {
if ( o implements serialize ) {
ps.setBytea(i, objsAsBtyea(o));
} else {
ps.setString(i, o.toString());
}
}
end loop
rs = ps.execute();
return rs; // representing the result of select * from my_java_function(with
this parameter);
But while searching for returning ResultSet examples I came across this old
thread. I am not sure if this is the best solution anyway ... what do you
think?
Thanks
Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pgfoundry.org/pipermail/pljava-dev/attachments/20110901/6406f17b/attachment.html>
From | Date | Subject | |
---|---|---|---|
Next Message | marc_firth | 2011-09-04 10:19:21 | [Pljava-dev] PostgresSQL 8.4 PL/Java IO access issue. |
Previous Message | John R Pierce | 2011-08-29 06:21:53 | [Pljava-dev] question on reading files using PL/Java |