It depends on what you mean by "backup." If you want to dump the database, you can do this with the dbms_datapump package.
Since this is a regular PL / SQL package, it can be easily called via JDBC. The simplest thing is probably to send the anonymous PL / SQL block as a single statement.
Something like that:
String sql = "DECLARE \n" + " handle NUMBER; \n" + "BEGIN \n" + " handle := DBMS_DATAPUMP.OPEN(operation => 'EXPORT', job_mode => 'SCHEMA', job_name => USER||'_DUMP', version => 'COMPATIBLE'); \n" + " dbms_datapump.add_file(handle => handle, filename => 'db_backup', directory => 'EXPDP_DIR'); \n" + " dbms_datapump.metadata_filter(handle, 'SCHEMA_LIST', '''SCOTT'''); \n" + " dbms_datapump.start_job(handle); \n" + " dbms_datapump.detach(handle); \n" + "END;"; Statement stmt = connection.createStatement(); stmt.execute(sql);
Please note that I did not consider error handling. Alternatively, you can call each dbms_datapump procedure individually (using CallableStatement )
The dump will be recorded on the server, not on the client!
See the manual for more details:
http://docs.oracle.com/cd/E11882_01/appdev.112/e25788/d_datpmp.htm
source share