2016-04-17 27 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。