1, establish the remote database connection:
public static synchronized Connection Getconfromremote () {
Connection con = null;
String url = "Jdbc:sqlserver://admin.xxx.xxx.comdbo:1436;databasename=remote_jadepool";
String userName = "hkm12345";
String password = "pwd12345";
try {
class.forname ("Com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = drivermanager.getconnection (URL, userName, password);
} catch (SQLException ex1) {
ex1.printstacktrace ();
} catch (ClassNotFoundException ex) {
Ex.printstacktrace ();
}
return con;
}
2, establish the Local database connection
public static synchronized Connection getconfromlocal () {
Connection con = null;
String url = "Jdbc:sqlserver://127.0.0.1dbo:1436;databasename=jadepool";
String userName = "hkm123";
String password = "pwd123";
try {
class.forname ("Com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = drivermanager.getconnection (URL, userName, password);
} catch (SQLException ex1) {
ex1.printstacktrace ();
} catch (ClassNotFoundException ex) {
Ex.printstacktrace ();
}
return con;
}
3, the remote database to save the data to the local database
public void BackupDB () {
Jade j0 = new Jade (Getconfromremote (), cn.jadepool.sql.DbConnectionType.USING_DB_01);
list<map> V0 = J0.query ("SELECT * from Jade_book");
List<map> V1 = j0.query ("SELECT * from Jade_book_cs");
J0.commit ();
Jade J1 = new Jade (getconfromlocal (), cn.jadepool.sql.DbConnectionType.USING_DB_02);
J1.delete ("Delete from Jade_book");
J1.insert ("Jade_book", v0);
J1.delete ("Delete from Jade_book_cs");
J1.insert ("Jade_book_cs", v1);
J1.commit ();
}
The two same databases are shown here, and the results are not affected by using a different database, but the structure of both tables must be consistent.