1.从www.postgresql.org下载最新的postgresql-snapshot.tar.gz,antfromapache;
2.settingant_home
3.../configure--with-java;make;makeinstall
function和java代码参考了jdbc.postgresql.orgmailinglist里面的内容.
createtableusers(idint,namevarchar(32));
createorreplacefunctionsp_users_select()returnsrefcursor
as'
declarerefrefcursor;
begin
openrefforselect*fromusers;
returnref;
end;
'languageplpgsql;
importjava.lang.*;
importjava.sql.*;
publicclasspc
{
publicstaticvoidmain(string[]args)
throwsexception
{
stringdriver ="org.postgresql.driver";
stringurl ="jdbc:postgresql://localhost:5432/nop";
stringuser ="nop";
stringpasswd ="nop";
class.forname(driver);
connectionconn =drivermanager.getconnection(url,user,passwd);
conn.setautocommit(false);//returnrefcursormustwithinatransaction
callablestatementproc=conn.preparecall("{?=callsp_users_select()}");
proc.registeroutparameter(1,types.other);
proc.execute();
resultsetresult=(resultset)proc.getobject(1);
system.out.println(result);
while(result.next())
{
system.err.println("name:"+result.getstring(2));
}
conn.commit();
}
}
新闻热点
疑难解答