JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » JDBC/SQL討論區 » Oracle  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
作者 Oracle Procedure Update問題...
hunterfish





發文: 28
積分: 0
於 2010-03-22 11:10 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
各位前輩好,
小弟有些問題想請教一下大家,

我目前是要利用Tigger,當有一筆新的資料產生時,呼叫Procedure的Java檔案去修改資料庫裡的資料,以下是我大概的程式碼:

[Trigger]
1
2
3
4
5
6
CREATE OR REPLACE TRIGGER contact_t4 
BEFORE INSERT ON xxx
FOR EACH ROW
BEGIN
    java_contact_t4 (:NEW.EMPID);
END;


[Procedure]
1
2
3
CREATE OR REPLACE PROCEDURE java_contact_t4 (member_id_in NUMBER) AS
LANGUAGE JAVA
NAME 'ThrowAnError.contactTrigger(java.lang.Integer)';


[Java]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import java.sql.*;
import oracle.jdbc.*;
 
public class ThrowAnError
{
  public static void contactTrigger (int empNo) throws SQLException
  {
    Connection conn = DriverManager.getConnection("jdbc:default:connection:");
    String sql = "UPDATE xxx SET PROCESS = '1' WHERE EMPID = ?";
    try
    {
      PreparedStatement pstmt = conn.prepareStatement(sql);
      pstmt.setInt(1, empNo);
      pstmt.executeUpdate();
      pstmt.close();
    }
    catch (SQLException e)
    {
      System.err.println(e.getMessage());
    }
  }
}


程式Compile都不會有問題
但是當新增一筆檔案時它並不會Update欄位內的資料
可是我測試在sql字串裡執行Insert指令時就會執行成功

是因為利用Procedure呼叫Java檔案時不能使用update指令嗎??
還是該怎樣做修正呢??
不知道這邊各位前輩可以幫我解答這個問題嗎??
謝謝大家。


reply to postreply to post
作者 Re:Oracle Procedure Update問題... [Re:hunterfish]
kevin_1130_b





發文: 1
積分: 0
於 2010-06-21 16:09 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Hi!

You could modify part of your "procedure" code
from
"NAME 'ThrowAnError.contactTrigger(java.lang.Integer)';"
to
"NAME 'ThrowAnError.contactTrigger(int)';"
and I think your problem will be solved.

Kevin


reply to postreply to post
» JWorld@TW »  JDBC/SQL討論區 » Oracle

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8