Sql Server 2008

sqlserver 数据向oracle转移:

import java.lang.*;
import java.sql.*;
public class TestSql {
public static void main(String[] args) throws SQLException,
ClassNotFoundException {
/* jdbc的oracle连接 */
// String sDBDriver = “oracle.jdbc.driver.OracleDriver”;
/* odbc的连接 */
String oralce_sDBDriver = “oracle.jdbc.driver.OracleDriver”;
String oralce_sConnStr = “jdbc:oracle:thin:localhost:1521:orcl”;
/* jdbc的SQL server连接 */
// jdbc.url=jdbc:sqlserver://IP;instanceName=ProductDB;databaseName=product_index;selectMethod=cursor
String sqlServer_sDBDriver = “com.microsoft.sqlserver.jdbc.SQLServerDriver”;
String sqlServer_sConnStr = “jdbc:sqlserver://localhost:1433;DatabaseName=jyxm”;
// 客户端游标
// String sConnStr =
// “jdbc:sqlserver://localhost:1433; DatabaseName=mahanso”;//;selectMethod=cursor
// 服务器端游标
// String sConnStrServerCursor =
// “jdbc:sqlserver://localhost:1433;DatabaseName=mahanso;selectMethod=cursor”;
String sqlServer_UserName = “sa”;
String sqlServer_PassWord = “*******”;
String oralce_UserName = “system”;
String oralce_PassWord = “********”;
// 登记驱动
Class.forName(oralce_sDBDriver);
Class.forName(sqlServer_sDBDriver);
// 连接到数据库
Connection cn_oracle = DriverManager.getConnection(oralce_sConnStr,
oralce_UserName, oralce_PassWord);
Connection cn_sqlserver = DriverManager.getConnection(
sqlServer_sConnStr, sqlServer_UserName, sqlServer_PassWord);
Statement s_oracle = cn_oracle.createStatement();
Statement s_sqlserver = cn_sqlserver.createStatement();
ResultSet rs = s_sqlserver
.executeQuery(“select * from area where id between 1 and 20000″);
// 字段1
// 字段2
String name = new String(“1″);
// 字段3
int deep= new Integer(1);
int parentid = new Integer(1);
// 向oracle数据库插入数据
while (rs.next()) {
name = rs.getString(“name”);
deep = rs.getInt(deep);
parentid = rs.getInt(parentid);
s_oracle.execute(“insert into area values(‘+name+’,'+deep+’,'+parentid+’)”);
}
}
}
方法2:任务——导出——for Oracle——连接Oracle——复制表——ssis——完成

你可能感兴趣的:(sqlserver2008)