这是我的功能:
public static void execute_delete_on_db(String pass, String login, String port, String host, String table_name, String file_path) throws Exception { Class.forName("oracle.jdbc.OracleDriver"); Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@//" + host + ":" + port + "/xe", login, pass); PreparedStatement statement = null; Statement stmt = null; String query = "delete from AA_ALL"; stmt = conn.createStatement(); stmt.executeQuery(query); sql_statement.close(); conn.commit(); conn.close(); }
至少这是我功能中最重要的部分。上面的代码工作正常。我试图通过调用以下sql语句来执行我的过程:
EXECUTE delete_all_rows_from_table('all');
在Java中,它看起来像这样:
String query = "EXECUTE delete_all_rows_from_table('all')";
在数据库上,它工作正常,但是在Java中,这给了我错误。你能告诉我我在做什么错吗?
您可以call执行过程,而不要像这样执行它:
call
String query = "{call delete_all_rows_from_table(?)}"; CallableStatement statement = connection.prepareCall(query); statement.setString(1, "all"); statement.execute();
您可以在此处了解更多信息:JDBC CallableStatement- 存储过程OUT参数示例和JDBC存储过程