SQLSERVER到ORACLE的数据库迁移
来源:互联网 发布:苹果怎么清除app数据 编辑:程序博客网 时间:2024/05/07 03:37
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
/**
* @中华人民共和国行政区划代码 迁移
* @模块: Regionalism.java
* @技术: JavaBean
* @版权: Copyright (c) 2005-2006 by ChenTuo. All Rights Reserved.
* @版本: Client V1.0
* @作者: Chen Tuo
*/
public class Regionalism
{
private java.sql.Connection con = null;
private final String url = "jdbc:microsoft:sqlserver://";
private final String serverName= "localhost";
private final String portNumber = "1433";
private final String databaseName= "NH_ND";
private final String userName = "sa";
private final String password = "";
private final String selectMethod = "cursor";
private java.sql.Connection conn = null;
// 构造函数
public Regionalism()
{
}
private String getConnectionUrl()
{
return url+serverName+":"+portNumber+";databaseName="+databaseName+";selectMethod="+selectMethod+";";
}
private java.sql.Connection getConnection()
{
try
{
// A. 注册 SQL Server JDBC 驱动程序
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
// B. 创建新数据库连接
con = java.sql.DriverManager.getConnection(getConnectionUrl(),userName,password);
if(con!=null) System.out.println("SQL Server Connection Successful!");
}
catch(Exception e)
{
e.printStackTrace();
System.out.println("Error SQL Server Trace in getConnection() : " + e.getMessage());
}
return con;
}
private java.sql.Connection getOracleConnection()
{
try
{
// A. 注册 Oracle JDBC 驱动程序
Class.forName("oracle.jdbc.driver.OracleDriver");
// B. 创建新数据库连接
conn = java.sql.DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:flow", "debug" ,"debug");
if(conn!=null) System.out.println("Oracle Connection Successful!");
}
catch(Exception e)
{
e.printStackTrace();
System.out.println("Error Oracle Trace in getConnection() : " + e.getMessage());
}
return conn;
}
private void closeSQLServerConnection()
{
try
{
if(con!=null)
con.close();
con=null;
}
catch(Exception e)
{
e.printStackTrace();
}
}
private void closeOracleConnection()
{
try
{
if(conn!=null)
conn.close();
conn=null;
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void displayDbProperties()
{
java.sql.DatabaseMetaData dm = null;
String InsertStatement ="";
try
{
con = this.getConnection();
conn = this.getOracleConnection();
if(con!=null && conn!=null)
{
// C. 创建 Statement 对象
Statement stmt = con.createStatement();
Statement stmtOracle = conn.createStatement();
// D. 执行 SELECT 命令,查询结果存放在 ResultSet 对象中
ResultSet rset = stmt.executeQuery("SELECT * FROM POLEINFO");
// E. 取得 ResultSet 结果集相关的信息
ResultSetMetaData md = rset.getMetaData();
// F. 取得 ResultSet 对象中的字段数量
int no_cols = md.getColumnCount();
String[] col_names = new String[no_cols];
// G. 取得 ResultSet 对象中各字段名称
for (int i = 0; i < no_cols; i++)
col_names[i] = md.getColumnLabel(i+1);
// H. 先打印出各字段名称
for (int i = 0; i < no_cols; i++)
System.out.print(col_names[i]+"/t");
System.out.println("/n---------------------------------------");
// I. 打印每笔数据列中各字段数据
while (rset.next())
{
/*for (int i = 1; i <= no_cols; i++)
System.out.print(rset.getString(i) + "/t");
System.out.println("");*/
// J. 数据插入 Oracle 中
InsertStatement = "INSERT INTO POLEINFO VALUES ("+rset.getString(1) + ",'" + rset.getString(2) + "','" +
rset.getString(3) + "','" + rset.getString(4)+ "','" + rset.getString(5)+ "','" + rset.getString(6)+ "')";
//注意 "'" 的应用,number类型没有 "'" ,varchar 用
System.out.print(InsertStatement+"/n");
stmtOracle.executeUpdate(InsertStatement);
}
rset.close();
rset = null;
stmt.close();
closeSQLServerConnection();
closeOracleConnection();
}
else
System.out.println("Error: No active Connection");
}
catch(Exception e)
{
e.printStackTrace();
}
dm=null;
}
public static void main(String[] args)
{
try
{
Regionalism regionalism = new Regionalism();
regionalism.displayDbProperties();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
- SQLSERVER到ORACLE的数据库迁移
- 如何将本地sqlserver的2000万数据迁移到虚拟机中的Oracle数据库里面
- 从oracle到Sqlserver数据库的数据迁移(图文详解)
- sqlserver数据库迁移到mysql的方法和步骤
- sqlserver数据库迁移到mysql的方法和步骤
- 数据库的迁移总结及区别比较(Oracle,MySQL,SQLServer)
- sqlserver数据库迁移至oracle数据库
- 数据迁移:从SqlServer到Oracle
- MYSQL数据迁移到ORACLE、SQLSERVER
- 将SqlServer迁移到oracle通过sqldeveloper
- MySQL数据库数据迁移到SQLserver
- 【数据库】从mysql迁移到sqlserver
- MySQL数据库数据迁移到SQLserver
- SqlServer数据库迁移到mysql实践
- 数据库迁移:mysql迁移到oracle
- postgresql数据库迁移到oracle
- MySQL数据库迁移到Oracle
- sqlserver数据库转存到oracle
- 关于写书
- 提高Google Adsense的eCPM的常用技巧
- MS SQL Server中的CONVERT日期格式化大全
- setjmp和longjmp函数
- php项目的一些函数
- SQLSERVER到ORACLE的数据库迁移
- 心得
- 开始Python -- 控制语句(1)
- Symbian系统的字体集合
- 程序员如何掌握计算机英语
- SQL 2005作为RMS的Database的问题
- asp.net用js的alert显示变量
- ASP.NET 2.0+GridView开发中遇到ViewState MAC验证错误
- symbian字体使用方法汇总