问题
I am making a small application and I am using the embedded derby database ,I want the application to be able to save the whole database onto a single file which can be stored on the hard drive and also import the database by opening this file in the future.Any clues or examples on how can I do it?
回答1:
This might help you out!
1- Resource 1 with all detail
2- Resource 2 with Export Detail only
3- Using Java to Export/Import Using Jdbc
To export all the data from a table to a single export file, including the LOB data
SYSCS_UTIL.SYSCS_EXPORT_TABLE (IN SCHEMANAME VARCHAR(128), IN TABLENAME VARCHAR(128), IN FILENAME VARCHAR(32672), IN COLUMNDELIMITER CHAR(1), IN CHARACTERDELIMITER CHAR(1), IN CODESET VARCHAR(128))
To export the result of a SELECT statement to a single file, including the LOB data
SYSCS_UTIL.SYSCS_EXPORT_QUERY (IN SELECTSTATEMENT VARCHAR(32672), IN TABLENAME VARCHAR(128), IN FILENAME VARCHAR(32672), IN COLUMNDELIMITER CHAR(1), IN CHARACTERDELIMITER CHAR(1), IN CODESET VARCHAR(128))
Import and export procedures from JDBC
You can run import and export procedures from a JDBC program.
The following code fragment shows how you might call the SYSCS_UTIL.SYSCS_EXPORT_TABLE procedure from Java. In this example, the procedure exports the data in the staff table in the default schema to the staff.dat file. A percentage (%) character is used to specify the column delimiter.
PreparedStatement ps=conn.prepareStatement(
"CALL SYSCS_UTIL.SYSCS_EXPORT_TABLE (?,?,?,?,?,?)");
ps.setString(1,null);
ps.setString(2,"STAFF");
ps.setString(3,"staff.dat");
ps.setString(4,"%");
ps.setString(5,null);
ps.setString(6,null);
ps.execute();
回答2:
Your question makes me wonder if you think you need to do this to persist your data. Just to be clear: You don't - your data is persisted on disk automatically. In fact all inserts and updates that have been committed are guaranteed to be persisted even if the jvm or machine should crash (as long as the disk is intact and the disk's write cache has been disabled).
D
来源:https://stackoverflow.com/questions/18692158/derby-database-export-as-a-single-file