使用JDBC方式读取Kylin结果

使用JDBC方式读取Kylin结果

一、准备依赖

<?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">
   

    <dependencies>
        <dependency>
            <groupId>org.apache.kylin</groupId>
            <artifactId>kylin-jdbc</artifactId>
            <version>3.0.2</version>
        </dependency>
    </dependencies>

</project>

二、查询数据

import java.sql.*;

public class KylinTest {

    public static void main(String[] args) throws sqlException {

        //获取连接
        Connection connection = DriverManager.getConnection("jdbc:kylin://hadoop102:7070/gmall","ADMIN","KYLIN");

        //准备sql
        String sql = "select PROVINCE_NAME ,REGION_NAME,ACTIVITY_NAME,ACTIVITY_TYPE ,\n" +
                "  sum(ORIGINAL_TOTAL_AMOUNT) sum_org,max(BENEFIT_REDUCE_AMOUNT ) max_ben\n" +
                "from DWD_FACT_ORDER_INFO t1\n" +
                "left join \n" +
                "DWD_DIM_BASE_PROVINCE  t2 on t1.PROVINCE_ID = t2.ID \n" +
                "left join\n" +
                "DWD_DIM_ACTIVITY_INFO_VIEW t3 on t1.ACTIVITY_ID = t3.id\n" +
                "group by PROVINCE_NAME ,REGION_NAME,ACTIVITY_NAME,ACTIVITY_TYPE ";

        //预编译sql
        PreparedStatement ps = connection.prepareStatement(sql);

        //执行sql
        ResultSet resultSet = ps.executeQuery();

        //遍历结果(迭代器使用haveNext的方式读取数据)
        while (resultSet.next()){

            System.out.println(resultSet.getString("PROVINCE_NAME") + "   " +
                    resultSet.getString("REGION_NAME") + "   " +
                    resultSet.getString("ACTIVITY_NAME") + "   " +
                    resultSet.getString("ACTIVITY_TYPE") + "   " +
                    resultSet.getBigDecimal("sum_org") + "   " +
                    resultSet.getBigDecimal("max_ben"));
        }

        //关闭资源
        resultSet.close();
        connection.close();


    }


}

相关文章

连接数据库的方式:第一种方式:ODBC:开放数据库连接是微软...
JDBCRequest 使用VariableNamesmysql:数据库连接池对象var...
 1.JDBCDBC(JavaDataBaseConnectivity):Java数据库连接技术...
1.需要jar包的支持:java.sqljavax.sqlmysql-conneter-java....
1.简介Activiti是一个业务流程管理(BPM)框架,它是覆盖了业务...
1.JDBC体系系统一组规范:接口JDBC接口(API)包括两个层次:...