At the request of many friends, I often want to migrate databases at work. I used my spare time to compile a migration instance. Friends who need this can learn from and correct me!
Ben
For example, the main implementation of Oracle to access migration, integrated use of Java JDBC driver and JDBC-ODBC bridge respectively to connect Oracle database management system and
Access database, the same is true for other data migration, but the connection method is modified! In this example, the data obtained from Oracle is directly inserted into the data table corresponding to access. Note:
Maintain table structure consistency between two databases during migration.
The raw data in Oracle and the data in the data table migrated to the Access Database
Idname login Meny salary
--------------------------------------------
1. Eclipse Technology Department 2500
2 Daxia Development Department 3000
3 Tianyi Technology Department 5000
4 Captain Development Department 4000
In this example, we need to import the corresponding Oracle JDBC package to connect to Oracle. The following is the code of datapass. Java:
Package datamanage;
Import java. SQL. connection;
Import java. SQL. drivermanager;
Import java. SQL. preparedstatement;
Import java. SQL. resultset;
Import java. SQL. statement;
Public class datapass {
Public static void main (string [] ARGs ){
String servername = "localhost ";
Try
{
Class. forname ("oracle. JDBC. Driver. oracledriver ");
String url = "JDBC: oracle: thin: @" + servername + ": 1521: eclipsedb ";
Connection connoracle = drivermanager. getconnection (URL, "Eclipse", "888888"); // connect to the source data source
Statement stmt = connoracle. createstatement ();
Resultset rs = stmt.exe cutequery ("select * from employee ");
Class. forname ("Sun. JDBC. ODBC. jdbcodbcdriver ");
Connection connaccess = drivermanager. getconnection ("JDBC: ODBC: Target", "", ""); // connect to the target data source
Preparedstatement pstmt = connaccess. preparestatement ("insert into employee (ID, name, department, salary) values (?,?,?,?) ");
// Cyclically load data
While (Rs. Next ()){
Pstmt. setint (1, Rs. getint ("ID "));
Pstmt. setstring (2, Rs. getstring ("name "));
Pstmt. setstring (3, Rs. getstring ("Department "));
Pstmt. setdouble (4, Rs. getdouble ("salary "));
Pstmt.exe cuteupdate ();
}
// Release resources
Rs. Close ();
Stmt. Close ();
Pstmt. Close ();
Connoracle. Close ();
Connaccess. Close ();
} Catch (exception e ){
E. printstacktrace ();
}
}
}
;
In this example, pay attention to the following:
1. Use different database connection methods. Pay attention to the preliminary data configuration and external package import;
2. Pay attention to the release of resources to ensure that the inserted data is fully saved;
Principles to be followed:
1. Complete Record-related data information;
2. data is stored in different data tables according to different types of data;
3. establish the relationship between the table and determine relevant fields;
4. Try to avoid repeated data storage!