从orale数据库中的表迁到sqlserver数据库表中

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
public class DataConvert1 {
 
 
 public static void main(String[] args){
  Connection countConn=null;
  Connection tsgConn=null;
  ResultSet tsgRs=null;
  Statement tsgStmt=null;
  String querySQL="select card,name,password,idcard,sex from reader where card like 'XXX%'";
  String insertSQL=null;
  try{
   countConn=DataConvert1.GetCountConnection();
   tsgConn=DataConvert1.GetTsgConnection();
   tsgStmt=tsgConn.createStatement();
   tsgRs=tsgStmt.executeQuery(querySQL);
   int index=1;
   while(tsgRs.next()){
    System.out.println(index);
    String bankcard=tsgRs.getString("card");
    String name=tsgRs.getString("name");
    String password=tsgRs.getString("password");
    String idcard=tsgRs.getString("idcard");
    String sex=tsgRs.getString("sex");
    insertSQL="insert into user_readerbook(bankcard,name,password,idcard,sex) values ('"
    +bankcard+"','"+name+"','"+password+"','"+idcard+"','"+sex+"')";
    
    DataConvert1.InsertCount(insertSQL, countConn);
    index++;
   }
  }catch(Exception e){
   e.printStackTrace();
  }finally{
   try{
    if(tsgRs!=null)
     tsgRs.close();
    if(tsgStmt!=null)
     tsgStmt.close();
    if(countConn!=null)
     countConn.close();
    if(tsgConn!=null)
     tsgConn.close();
   }catch(Exception e){
    e.printStackTrace();
   }
  }
  
 }
 
 
 
 static String DBdriver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
 static String url="jdbc:sqlserver://localhost; DatabaseName=ku";
 static String user="root";
 static String password="pwd";
 
 static String tsgDBdriver="oracle.jdbc.driver.OracleDriver";
 static String tsgurl="jdbc:oracle:thin:@localhost:1521:ku";
 static String tsguser="root";
 static String tsgpassword="pwd";
 
 public static Connection GetCountConnection(){
  Connection conn=null;
  try{
   Class.forName(DBdriver);
      conn=DriverManager.getConnection(url,user,password);
     
  }catch(ClassNotFoundException e){
   e.printStackTrace();
  }catch(SQLException e){
   e.printStackTrace();
  }
  return conn;
 }
 public static Connection GetTsgConnection(){
  Connection conn=null;
  try{
   Class.forName(tsgDBdriver);
      conn=DriverManager.getConnection(tsgurl,tsguser,tsgpassword);
     
  }catch(ClassNotFoundException e){
   e.printStackTrace();
  }catch(SQLException e){
   e.printStackTrace();
  }
  return conn;
 }
 public static void InsertCount(String sql,Connection conn){
  Statement stmt=null;
  try{
   conn.setAutoCommit(false);
   stmt=conn.createStatement();
   int rows=stmt.executeUpdate(sql);
   if(rows>0){
    conn.commit();
   }else{
    System.out.println("Ok:"+sql);
   }
  }catch(Exception e){
   e.printStackTrace();
  }finally{
   try{
    if(stmt!=null)
     stmt.close();
    stmt=null;
    
   }catch(Exception e){
    e.printStackTrace();
   }
  }
 }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值