2017-02-02 113 views
1

執行過程。這是我的函數:如何使用JDBC

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中,這是給我的錯誤。 你能告訴我我做錯了什麼嗎?

+1

閱讀文檔https://docs.oracle.com/cd/E17952_01 /connector-j-en/connector-j-usagenotes-statements-callable.html – JIV

+0

你得到了什麼錯誤? –

+2

@JIV在涉及Oracle數據庫時連接到MySQL文檔? – Gimby

回答