Phoenix HBase Java常用的API

Phoenix HBase Java常用的API

下面是Java通过jdbc向Phoenix取hbase数据的代码

package org.example;
import org.apache.phoenix.jdbc.PhoenixDriver;


import org.junit.Test;
import java.sql.*;

public class HbasePhoenixJDBCTest {
    
    

    @Test
    public static void main(String[] args) throws SQLException {
    
    
        Connection connection = null;
        PreparedStatement ps = null;
        try {
    
    
            Class.forName(PhoenixDriver.class.getName());
            connection = DriverManager.getConnection("jdbc:phoenix:node1.itcast.cn:2181");
            ps = connection.prepareStatement( "select user_id,payway,category from order_info");
            ResultSet rs = ps.executeQuery();
            while(rs.next()) {
    
    
                System.out.println(
                        rs.getString("USER_ID")+"\t"+
                                rs.getString("PAYWAY")+"\t"+
                                rs.getString("CATEGORY"));
            }
        }catch (Exception e){
    
    
            e.printStackTrace();
        }finally {
    
    
            if(ps != null) ps.close();
            if(connection != null) connection.close();
        }

    }
}

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>phoenix_java</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>



    <dependencies>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.phoenix/phoenix -->
        <dependency>
            <groupId>org.apache.phoenix</groupId>
            <artifactId>phoenix</artifactId>
            <version>5.0.0-HBase-2.0</version>
            <type>pom</type>
        </dependency>
        <!-- phoenix core -->
        <dependency>
            <groupId>org.apache.phoenix</groupId>
            <artifactId>phoenix-core</artifactId>
            <version>5.0.0-HBase-2.0</version>
        </dependency>
        <!-- phoenix 客户端 -->
        <dependency>
            <groupId>org.apache.phoenix</groupId>
            <artifactId>phoenix-queryserver-client</artifactId>
            <version>5.0.0-HBase-2.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-auth -->
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-auth</artifactId>
            <version>3.0.0</version>
        </dependency>

    </dependencies>



</project>

猜你喜欢

转载自blog.csdn.net/HELLOWORLD2424/article/details/130872970