1 /*
2 * To change this license header, choose License Headers in Project Properties.3 * To change this template file, choose Tools | Templates4 * and open the template in the editor.5 */
6 packagecom.phkj.phoenixtest2;7
8
9 importjava.sql.Connection;10 importjava.sql.DriverManager;11 importjava.sql.ResultSet;12 importjava.sql.SQLException;13 importjava.sql.Statement;14
15 importorg.antlr.grammar.v3.TreeToNFAConverter.set_return;16 importorg.apache.phoenix.jdbc.PhoenixDriver;17 importorg.omg.CORBA.INTERNAL;18 importorg.python.antlr.ast.boolopType;19
20 public classOrecal2Phoniex {21
22 public static void main(String[] args) throwsClassNotFoundException, SQLException {23
24 //1、加载驱动
25 Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");26 //Class.forName("oracle.jdbc.driver.OracleDriver");
27 System.out.println("加载phoneix、oracle驱动");28 //2、建立连接
29 Connection connPhoenix = null;30 Connection conn = null;31 try{32 System.out.println("123");33 connPhoenix =DriverManager.getConnection("jdbc:phoenix:ip号:端口号","","");34 //conn =DriverManager.getConnection("jdbc:oracle:thin:@oracle ip地址:orcl", "账号", "密码");
35 System.out.println("Phoenix、oracle 连接成功!");36 } catch(SQLException e) {37 System.out.println("Phoenix、oracle 连接失败!");38 }39
40 //3、操作句柄
41 Statement stmt=null,stmt1=null,stmt2=null;42 try{43 stmt=connPhoenix.createStatement();44 System.out.println("获取句柄成功");45 } catch(SQLException e) {46 System.out.println("获取句柄失败");47 }48
49 //4、sql操作
50 String sql=null,51 sql1="select * from CS_T_cust_contact_info";52
53 ResultSet rs=stmt.executeQuery(sql1);54 Integer n=0,m=0;55 /*while (rs.next()){56 n++;57 Integer ID=rs.getInt("ID");58 String CUST_NAME = rs.getString("CUST_NAME");59 String REG_PROV = rs.getString("REG_PROV");60 Integer LOAN_MONEY=rs.getInt("LOAN_MONEY");61 sql="upsert into CS_T1_CUST_BASE_INFO(ID,CUST_NAME,REG_PROV,LOAN_MONEY) values"62 + "("+ID+",‘"+CUST_NAME+"‘,‘"+REG_PROV+"‘,"+LOAN_MONEY+")";63 stmt.executeUpdate(sql);64 if (n%10000==0){65 m++;66 connPhoenix.commit();67 System.out.println("提交"+m+"次");68 }69
70
71 }*/
72 while(rs.next()){73 n++;74 Integer ID=rs.getInt("ID");75 String CUST_NO = rs.getString("CUST_NO");76 sql="upsert into CS_T1_cust_contact_info(ID,CUST_NO) values"
77 + "("+ID+",‘"+CUST_NO+"‘)";78 stmt.executeUpdate(sql);79 if (n%10000==0){80 m++;81 connPhoenix.commit();82 System.out.println("提交"+m+"次");83 }84 }85
86
87 /*for (int id = 1 ; id<=1640000 ;id++){88 if( id%4 ==1){89 sql="upsert into CS_T_CUST_BASE_INFO(id,LOAN_MONEY) values("+id+","+2500+")";90 }else if (id%4 == 2){91 sql="upsert into CS_T_CUST_BASE_INFO(id,LOAN_MONEY) values("+id+","+3000+")";92 }93 else if (id%4 == 3){94 sql="upsert into CS_T_CUST_BASE_INFO(id,LOAN_MONEY) values("+id+","+3500+")";95 }96 stmt.executeUpdate(sql);97
98 if (id%5000==0){99 connPhoenix.commit();100 System.out.println("提交");101 }102
103 }*/
104
105 //5、关闭连接
106 stmt.close();107 connPhoenix.close();108 }109 }