Data integration (EAI) between applications is usually two roads:
First, use the ready-made EAI, ETL framework to define a pile of XML format map files, and then write some special conversion TRANSFORM CLASS. But such projects are usually more grand, and they will often find out if they write programs.
Second, write the program directly with JDBC-> SQL conversion, fast, but often written more chaos, especially how many columns are many columns.
So, I will use universal old DBUNIT DOM4J to export import. DBUNIT can be held in many places because of XML <-> Database features. Write EAI with XML, which is clear than the SQL statement, and the effect and write mapping files are similar, but because all written in the program, it is not as mapped to the EAI framework, and the conversion class turns around to see it. In addition, it belongs to Refresh (if there is no insertion, otherwise update, based on the primary key), clean_insert (all deleted re-insert, and refresh ratio, will delete data from the data in XML), etc. Dedicated to programming skills.
Example code:
// Dom4j and assign the value creation Document Document document = DocumentHelper.createDocument (); document.addElement ( "dataset"); Element root = document.getRootElement (); while (rs.next ()) {item.attribute ( " BS "). setValue (rs.getstring (" orderitemno ")); root.add (item.createcopy ());}
// Convert DocumentH to DataSet with DBUnit and resolve Chinese Coding Issues InputSource IS = New Documentsource (Document) .GetinputSource (); is.setencoding ("GBK"); iDataSet DataSet = New Flatxmldataset (IS);
// Establish a DBUnit database connection connection conn = .....; DatabaseConnection Dbcon = New DatabaseConnection (conn); // Perform Insert DatabaseOperation.Insert.execute (DBCON, DATASET);
In addition, in my project, there are many unclear columns in the target database (about 200), do not fill it, will be wrong, fill it, don't know what to fill. So, I first sampled it with DBUnit, Item is a sample obtained from the target database. In the process of establishing Document, I keep using Item.createCopy () to bring this sample, only share some sources The value of the need to change is required. This is a bonus in dbunit :)