returns setof refcursor
berarti Anda mendapatkan ResultSet
regular biasa di mana setiap "baris" berisi lainnya ResultSet saat memanggil getObject()
:
Berikut ini berfungsi untuk saya:
ResultSet rs = stmt.executeQuery("select * from usp_sel_article_initialdata_new1()");
if (rs.next())
{
// first result set returned
Object o = rs.getObject(1);
if (o instanceof ResultSet)
{
ResultSet rs1 = (ResultSet)o;
while (rs1.next())
{
int id = rs1.getInt(1);
String name = rs1.getString(2);
.... retrieve the other columns using the approriate getXXX() calls
}
}
}
if (rs.next())
{
// process second ResultSet
Object o = rs.getObject(1);
if (o instanceof ResultSet)
{
ResultSet rs2 = (ResultSet)o;
while (rs2.next())
{
......
}
}
}
Dari dalam psql
anda juga dapat menggunakan select * from usp_sel_article_initialdata_new1()
Anda hanya perlu menggunakan FETCH ALL
setelah itu. Lihat manual untuk contoh:http://www. postgresql.org/docs/current/static/plpgsql-cursors.html#AEN59018
postgres=> select * from usp_sel_article_initialdata_new1();
usp_sel_article_initialdata_new1
----------------------------------
<unnamed portal 1>
<unnamed portal 2>
(2 rows)
postgres=> fetch all from "<unnamed portal 1>";
?column?
----------
1
(1 row)
postgres=> fetch all from "<unnamed portal 2>";
?column?
----------
2
(1 row)
postgres=>
(Saya membuat fungsi dummy untuk contoh di atas yang hanya mengembalikan satu baris dengan nilai 1
untuk kursor pertama dan 2
untuk kursor kedua)
Sunting :
Agar ini berfungsi, ini perlu dijalankan di dalam transaksi. Oleh karena itu autocommit harus dimatikan:
connection.setAutoCommit(false);