|
发表于 2011-10-31 14:13:53
|
显示全部楼层
Re:
如果在sqlserver有一个存儲过程要在postgreSQL中实现,是不是要写成创建函数的显示?
是
转:
postgresql的存储过程,在java中如何使用。http://www.chinaunix.net/jh/18/116278.html
POSTGRESQL的JDBC中的存储过程
http://www.chinaunix.net 作者:joint 发表于:2003-07-16 23:29:26
1. 從www.postgresql.org下载最新的postgresql-snapshot.tar.gz, ant from apache;
2. setting ANT_HOME
3. ../configure --with-java; make; make install
FUNCTION 和 JAVA 代码参考了jdbc.postgresql.org mailing list里面的内容.
CREATE TABLE users (id int, name varchar(32));
CREATE OR REPLACE FUNCTION sp_users_select () RETURNS refcursor
AS '
declare ref refcursor;
begin
open ref for select * from users;
return ref;
end;
' LANGUAGE plpgsql;
import java.lang.*;
import java.sql.*;
public class pc
{
public static void main(String[] args)
throws Exception
{
String driver = "org.postgresql.Driver";
String url = "jdbc:postgresql://localhost:5432/nop";
String user = "nop";
String passwd = "nop";
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, user, passwd);
conn.setAutoCommit(false); // return refcursor must within a transaction
CallableStatement proc = conn.prepareCall("{ ? = call sp_users_select () }";
proc.registerOutParameter(1, Types.OTHER);
proc.execute();
ResultSet result = (ResultSet) proc.getObject(1);
System.out.println(result);
while(result.next())
{
System.err.println("Name : " + result.getString(2));
}
conn.commit();
}
} |
|