-4

我在 PostgreSQL 9.1 中定义了一个触发器,它应该在记录更新时触发:

CREATE OR REPLACE FUNCTION check() RETURNS TRIGGER AS $$
 BEGIN
   SELECT doubletEngine.checkForDoublet(NEW.id);
 RETURN NEW;
END;
$$ LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS check_upd on people;
CREATE TRIGGER check_upd AFTER UPDATE ON people
  FOR EACH ROW
  WHEN (OLD.* IS DISTINCT FROM NEW.*)
  EXECUTE PROCEDURE check();

方法 doubletEngine.checkForDoublet() 被引入 PL/Java 1.4.3 使用

CREATE OR REPLACE FUNCTION doubletEngine.checkForDoublet(varchar) RETURNS void AS 'DoubletSearcher.checkForDoublet' LANGUAGE java;

在方法 checkForDoublet() 中,我尝试使用

Class.forName("org.postgresql.Driver");
String url = "jdbc:postgresql://127.0.0.1:5432/db";
c = DriverManager.getConnection(url, "postgres", "postgres");
if ( c == null ) {
   throw new RuntimeException("Could not connect to server");
}

...但 c 仍然为空。直接从我的 IDE 调用此代码效果很好,但是当触发器触发时,它只会抛出 RuntimeException。有什么我想念的吗...???

4

1 回答 1

1

根据 PL/Java文档,连接应该如下获得:

Connection conn = DriverManager.getConnection("jdbc:default:connection"); 
于 2012-05-29T12:24:46.023 回答