- 相關(guān)推薦
如何利用Java技術(shù)實(shí)現(xiàn)兩個(gè)不同數(shù)據(jù)庫(kù)之間的數(shù)據(jù)交換
利用Java技術(shù)實(shí)現(xiàn)兩個(gè)不同數(shù)據(jù)庫(kù)之間的數(shù)據(jù)交換的方法有哪些你知道嗎?你知道如何利用Java技術(shù)實(shí)現(xiàn)兩個(gè)不同數(shù)據(jù)庫(kù)之間的數(shù)據(jù)交換嗎?下面是小編為大家?guī)?lái)的如何利用Java技術(shù)實(shí)現(xiàn)兩個(gè)不同數(shù)據(jù)庫(kù)之間的數(shù)據(jù)交換的知識(shí),歡迎閱讀。
1、建立遠(yuǎn)程數(shù)據(jù)庫(kù)的連接:
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、建立本地?cái)?shù)據(jù)庫(kù)的連接
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、將遠(yuǎn)程數(shù)據(jù)庫(kù)的數(shù)據(jù)保存到本地?cái)?shù)據(jù)庫(kù)中
public void backupDB() {
Jade j0 = new Jade(getConFromRemote(), cn.jadepool.sql.DbConnectionType.USING_DB_01);
List v0 = j0.query("select * from jade_book");
List v1 = j0.query("select * from jade_book_cs");
j0.commit();
Jade j1 = new Jade(getConFromLocal(), cn.jadepool.sql.DbConnectionType.USING_DB_02);
j1.(" from jade_book");
j1.("jade_book", v0);
j1.(" from jade_book_cs");
j1.("jade_book_cs", v1);
j1.commit();
}
【如何利用Java技術(shù)實(shí)現(xiàn)兩個(gè)不同數(shù)據(jù)庫(kù)之間的數(shù)據(jù)交換】相關(guān)文章:
java利用反射實(shí)現(xiàn)動(dòng)態(tài)代理實(shí)現(xiàn)代碼05-18
如何利用Word實(shí)現(xiàn)網(wǎng)上開(kāi)會(huì)02-21
如何利用java讀取網(wǎng)絡(luò)照片01-08
java通用組合算法如何實(shí)現(xiàn)05-12
java如何利用java.net.URLConnection發(fā)送HTTP請(qǐng)求08-05
Java中如何實(shí)現(xiàn)顯示動(dòng)態(tài)的時(shí)間03-14