HiveBrain v1.2.0
Get Started
← Back to all entries
snippetjavaMinor

How can I execute a PL/SQL procedure for Oracle via JDBC?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
cansqljdbcprocedureviaforhoworacleexecute

Problem

I have a Java webapp with an Oracle DB, and I try to execute this statement at the end of a data migration script:

EXEC DBMS_STATS.GATHER_TABLE_STATS (ownname => 'MY_SCHEMA', tabname => 'MY_TABLE', estimate_percent => dbms_stats.auto_sample_size);


It works in sql*plus, but not via JDBC:

"Error: ORA-00900: invalid SQL statement"


What am I doing wrong?

Solution

Instead of EXEC, you should put it between begin ... end, or use the { call } syntax.
Here is an example, in the documentation:

http://docs.oracle.com/cd/E11882_01/java.112/e16548/getsta.htm#i1014127

Context

StackExchange Database Administrators Q#49723, answer score: 5

Revisions (0)

No revisions yet.