2016-04-17 42 views
0

我想使用Java代碼執行PL/SQL過程。到目前爲止,我已經試過這樣:使用Java代碼執行PL/SQL過程

Statement myStmt = null; 

myStmt = conn.createStatement(); 
myStmt.executeQuery("EXECUTE ProjetIRSTEA.detectionX"); 

我也得到了以下錯誤消息:

java.sql.SQLSyntaxErrorException: ORA-00900: invalid SQL statement 

回答

1

嘗試:

myStmt.executeUpdate("BEGIN ProjetIRSTEA.detectionX; END"); 

您還可以使用由JDBC標準定義調用存儲過程的方法使用CallableStatement的接口:

CallableStatement myCall = connection.prepareCall("{call ProjetIRSTEA.detectionX()}") 
myCall.executeUpdate(); 
0

在Oracle中,你可以使用eithe可以使用CallableStatement(如上所述)或者使用Statement或PreparedStatement發出一個普通的SQL查詢(但前者是首選方法)。

String sql = " select ProjetIRSTEA.detectionX() from dual"; 
PreparedStatement stmt = conn.prepareStatement(sql); 
stmt.execute(); 

請注意,您必須在您的select語句中引用系統表dual。