Database-related: migration between different databases

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.