码迷,mamicode.com
首页 > 数据库 > 详细

JDBC phoenix

时间:2017-10-24 14:14:12      阅读:988      评论:0      收藏:0      [点我收藏+]

标签:exce   base   nal   create   加载驱动   pac   ati   height   too   

1、首先确保引入以下两个包:

技术分享

2、通过phoenix连接

  1 /*
  2  * To change this license header, choose License Headers in Project Properties.
  3  * To change this template file, choose Tools | Templates
  4  * and open the template in the editor.
  5  */
  6 package com.phkj.phoenixtest2;
  7 
  8 
  9 import java.sql.Connection;
 10 import java.sql.DriverManager;
 11 import java.sql.ResultSet;
 12 import java.sql.SQLException;
 13 import java.sql.Statement;
 14 
 15 import org.antlr.grammar.v3.TreeToNFAConverter.set_return;
 16 import org.apache.phoenix.jdbc.PhoenixDriver;
 17 import org.omg.CORBA.INTERNAL;
 18 import org.python.antlr.ast.boolopType;
 19 
 20 public class Orecal2Phoniex {
 21     
 22     public static void main(String[] args) throws ClassNotFoundException, 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 }

 

JDBC phoenix

标签:exce   base   nal   create   加载驱动   pac   ati   height   too   

原文地址:http://www.cnblogs.com/ceshixuexi/p/7722972.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!