I'm currently using Oracle 11g R2 express edition. How can I back up my database using java application? Is it possible?
It depends on what you mean with "backup". If you want to create a dump of the database, you can do that using the dbms_datapump
package.
As it is a regular PL/SQL package it can easily be called through JDBC. The easiest thing is probably to send an anonymous PL/SQL block as a single statement.
Something like this:
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);
Note that I left out any error handling. Alternatively you can call each dbms_datapump
procedure individually (using a CallableStatement
)
The dump will will be written on the server, not on the client!
For more details please refer to the manual:
http://docs.oracle.com/cd/E11882_01/appdev.112/e25788/d_datpmp.htm
好吧,通常你可以,因为你可以提取数据和存储SQL结构(表,约束,索引等)你可能会发现有用这个你也可以使用YAML格式来存储数据。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.