(一)
備份**,以
dbunit2.2
版本為例; //
獲的connection
的乙個資料庫連線
connection jdbcconnection = webdb.getconnect();
//oracle
中必須指定
schema
,見引數「
zfcg」
idatabaseconnection connection =
newdatabaseconnection(jdbcconnection,
"zfcg");
string datafile =
"d://testdata";
string tablenames = ;
idataset actualdataset = connection.createdataset(tablenames);
flatxmldataset.write(actualdataset,newfileoutputstream(datafile));
(二)還原**
connection jdbcconnection = webdb.getconnect();
idatabaseconnection connection =
newdatabaseconnection(jdbcconnection,
"zfcg");
string datafile =
"d://testdata";
idataset expecteddataset =newflatxmldataset(newfileinputstream(datafile));
databaseoperation.
clean_insert
.execute(connection,expecteddataset);
(三)遇到問題;
1、oralce
資料中產生
ambiguoustablenameexception
的錯誤:
原因主要是
dbunit
中使用了
schema
,因此必須指定
schema
;資料庫
schema
,相當於方案,每個資料庫例項,裡面可能會有多個使用者,每個使用者可能都有自己的表,過程等
object
,那oracle
就會為每個使用者建立乙個與使用者名稱相同的方案,就相當於
schema。
值得注意的是,
schema
要求一定要大寫的,否則會產生
nosuchtableexception。
2、如何提高
dbunit
的匯入匯出效能?
使用dnunit
的需要注意一些和效能相關的配置。
1.使用
streame
的匯入匯出減少記憶體消耗,使用
streamingdataset
讀取dataset
,處理資料匯入。匯出時使用配置
dbunit
的連線使用
forwardonlyresultsettable
匯出資料
idatabaseconnection connection = new databaseconnection(jdbcconnection, schema);
databaseconfig config = connection.getconfig();
config.setproperty(databaseconfig.property_resultset_table_factory, new forwardonlyresultsettablefactory());
2.明確指定匯入匯出的
schema
3.如果
jdbc
支援批處理,請使用
dbunit
的批處理語句功能
資料備份還原
先加一快硬碟,重啟之後fdisk l 檢視一下硬碟是否能找到 然後fdisk dev sdb建立乙個主分割槽 root localhost mkfs.xfs dev sdb1 格式成xfs格式 root localhost mkdir data 建立乙個data目錄 root localhost m...
備份還原資料
備份mysql資料庫的命令 mysqldump hhostname uusername ppassword databasename backupfile.sql 備份mysql資料庫為帶刪除表的格式,能夠讓該備份覆蓋已有資料庫而不需要手動刪除原有資料庫。mysqldump add drop tab...
備份還原 資料庫備份和還原
最近在搞封閉開發,有些東西基本上都忘記了,在網上重新搜尋了一下貼子,總結了一下檔案組備份和還原的一些東西 環境 microsoft corporation developer edition on windows nt 5.1 build 2600 service pack 3,v.5755 1 建...