How to back up oracle database using java?

I am currently using Oracle 11g R2 express edition. How can I back up my database using a java application? Is it possible?

+4
source share
2 answers

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

+3
source

Well, as a rule, you can, because you can retrieve data and store the SQL structure (tables, constraints, indexes, etc.), you can find this useful You can also use the YAML format to store data.

0
source

All Articles