欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Apache Kylin 2.3 JDBC Java API 示例

程序员文章站 2024-03-22 16:18:34
...

官方文档
http://kylin.apache.org/docs23/tutorial/jdbc.html

1、pom.xml

<dependencies>
    <!-- https://mvnrepository.com/artifact/org.apache.kylin/kylin-jdbc -->
    <dependency>
        <groupId>org.apache.kylin</groupId>
        <artifactId>kylin-jdbc</artifactId>
        <version>2.3.1</version>
    </dependency>
    ...
  </dependencies>

2、Statement

package com.cntaiping.tpa.kylin;
import java.sql.Connection;  
import java.sql.DriverManager;
import java.sql.ResultSet;  
import java.sql.Statement;  
public class KylinDemo1 {

    public static void main(String[] args) throws Exception{
        String conStr = "jdbc:kylin://10.17.12.160:7070/learn_kylin";
        Class.forName("org.apache.kylin.jdbc.Driver");
        Connection conn = DriverManager.getConnection(conStr, "ADMIN", "KYLIN");  
        Statement state= conn.createStatement();  
        String sql="select part_dt, sum(price) as total_selled,count(distinct seller_id) as sellers " +  
                "from kylin_sales group by part_dt order by part_dt limit 5";
        ResultSet rs=state.executeQuery(sql);  
        System.out.println("part_dt\t"+ "\t" + "total_selled" + "\t" +"sellers");              
        while(rs.next()) {   
             System.out.println(rs.getString(1)+ "\t" +rs.getString(2) + "\t" +rs.getString(3));  
        }  
    }

}

运行结果

part_dt     total_selled    sellers
2011-12-31  466.9037    12
2012-01-01  970.2347    17
2012-01-02  917.4138    14
2012-01-03  553.0541    10
2012-01-04  732.9007    18

Apache Kylin 2.3 JDBC Java API 示例

3、PreparedStatement

package com.cntaiping.tpa.kylin;
import java.sql.Connection;  
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;  

public class KylinDemo2 {

    public static void main(String[] args) throws Exception{
        String conStr = "jdbc:kylin://10.17.12.160:7070/learn_kylin";
        Class.forName("org.apache.kylin.jdbc.Driver");
        Connection conn = DriverManager.getConnection(conStr, "ADMIN", "KYLIN");    
        String sql="select * from KYLIN_CATEGORY_GROUPINGS where LEAF_CATEG_ID = ?";
        PreparedStatement state = conn.prepareStatement(sql);  
        state.setLong(1,10058);  
        ResultSet rs= state.executeQuery();            
        while(rs.next()) {   
             System.out.println(rs.getString(1)+ "\t" +rs.getString(2) + "\t" +rs.getString(3));  
        }  
    }

}

Apache Kylin 2.3 JDBC Java API 示例

相关标签: Kylin JDBC Java