首页 > 开发 > 综合 > 正文

POSTGRESQL的JDBC中的存储过程

2024-07-21 02:13:48
字体:
来源:转载
供稿:网友

  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();
}
}

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表