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();
}
}
}
}
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();
}
}
}
}