Oracle plsql calling procedure using java
Oracle plsql calling procedure using java
When you need to call an Oracle stored procedure from Java JDBC, CallableStatement is the right approach. The {call procedure_name()} syntax is standard JDBC callable statement notation. Using try-with-resources ensures the connection and statement are properly closed even if an exception is thrown.
- sample procedure
1
2
3
4
5
6
7
8
9
10
11
12
13
14
create or replace procedure proc_truncate_table
is
begin
execute immediate 'truncate table data_table';
end;
* calling above procedure from jdbc
```console
try (Connection connection = getConnection()) {
try (CallableStatement statement = connection.prepareCall("{call proc_truncate_table()}")) {
statement.execute();
}
}
This post is licensed under
CC BY 4.0
by the author.