Kylin提供了标准的ODBC和JDBC接口,能够和传统BI工具进行很好的集成。分析师们可以用他们最熟悉的工具来享受Kylin带来的快速。我们也可以对它进行定制开发报表等,把kylin当做数据库服务器就行了。

首先我们来看一下连接Kylin的URL格式为:

jdbc:kylin://<hostname>:<port>/<kylin_project_name>

注:

如果“ssl”为true话,那么上面的端口号应该为Kylin服务的HTTPS端口号。

kylin_project_name必须指定,并且在Kylin服务中存在。

运行环境需要把安装文件的那个lib目录拷贝到自己的项目引用下

下面介绍几种方式访问Kylin数据:

第一种方法:使用Statement方式查询

第二种方法:使用PreparedStatement方式查询

第三种方法:获取查询结果集元数据

package org.apache.kylin.jdbc;

import java.sql.SQLException;
import java.util.Properties;
import org.junit.Test;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement; /**
* @author :
* @date : 2017年4月17日
* @version 1.0
* @parameter
*/
public class QueryKylinST { @Test
public void testStatementWithMockData() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {
// 加载Kylin的JDBC驱动程序
Driver driver = (Driver) Class.forName("org.apache.kylin.jdbc.Driver").newInstance(); // 配置登录Kylin的用户名和密码
Properties info= new Properties();
info.put("user","ADMIN");
info.put("password","KYLIN"); // 连接Kylin服务
Connection conn= driver.connect("jdbc:kylin://10.8.217.66:7070/learn_kylin",info);
Statement state= conn.createStatement();
ResultSet resultSet =state.executeQuery("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"); System.out.println("part_dt\t"+ "\t" + "total_selled" + "\t" +"sellers"); while(resultSet.next()) {
String col1 = resultSet.getString(1);
String col2 = resultSet.getString(2);
String col3 = resultSet.getString(3);
System.out.println(col1+ "\t" + col2 + "\t" + col3);
}
} @Test
public void testanylist() throws Exception {
Driver driver =(Driver) Class.forName("org.apache.kylin.jdbc.Driver").newInstance();
Properties info= new Properties();
info.put("user","ADMIN");
info.put("password","KYLIN");
Connection conn= driver.connect("jdbc:kylin://10.8.217.66:7070/learn_kylin",info); PreparedStatement state = conn.prepareStatement("select * from KYLIN_CATEGORY_GROUPINGS where LEAF_CATEG_ID = ?");
state.setLong(1,10058); ResultSet resultSet = state.executeQuery();
while (resultSet.next()) {
String col1 = resultSet.getString(1);
String col2 = resultSet.getString(2);
String col3 = resultSet.getString(3);
System.out.println(col1+ "\t" + col2 + "\t" + col3);
}
} @Test
public void testmetadatalist() throws Exception {
Driver driver = (Driver) Class.forName("org.apache.kylin.jdbc.Driver").newInstance();
Properties info = new Properties();
info.put("user", "ADMIN");
info.put("password", "KYLIN");
Connection conn = driver.connect("jdbc:kylin://10.8.217.66:7070/learn_kylin", info);
Statement state = conn.createStatement();
ResultSet resultSet = state.executeQuery("select * from kylin_sales"); //第三个是表名称,一般情况下如果要获取所有的表的话,可以直接设置为null,如果设置为特定的表名称,则返回该表的具体信息。
ResultSet tables = conn.getMetaData().getTables(null, null, null, new String[]{"TABLE"});
while (tables.next()) {
// for (int i = 0; i < 10; i++) {
// System.out.println(tables.getString(i + 1));
// }
String col1 = tables.getString(1); //表类别
String col2 = tables.getString(2); //表模式
String col3 = tables.getString(3); //表名称
System.out.println("表信息:"+col1+ "\t" + col2 + "\t" + col3);
}
}
}

结果如下:由于单元测试,先后顺序不一致,注意忽视

参考资料

http://kylin.apache.org/docs20/howto/howto_jdbc.html
http://www.cnblogs.com/en-heng/p/5420269.html Python Post方式
http://blog.csdn.net/linlinv3/article/details/53893144 Java 使用httpClient 进行post访问

Kylin如何进行JDBC方式访问或者调用的更多相关文章

  1. 2017.11.12 web中JDBC 方式访问数据库的技术

    JavaWeb------ 第四章 JDBC数据库访问技术 在JavaWeb应用程序中数据库访问是通过Java数据库连接(JavaDateBase Connectivity简称JDBC)数据库的链接一 ...

  2. Impala通过JDBC方式访问

    不多说,直接上干货! • 配置: – impala.driver=org.apache.hive.jdbc.HiveDriver – impala.url=jdbc:hive2://node2:210 ...

  3. 使用jdbc的方式访问kylin cube的数据

    使用jdbc的方式访问kylin cube的数据 引用kylin相关的jar包 <dependency> <groupId>org.apache.kylin</group ...

  4. Spring04-SpringEL&Spring JDBC数据访问

    一. SpringEL入门 Spring动态语言(简称SpEL) 是一个支持运行时查询和操作对象图的强大的动态语言,语法类似于EL表达式,具有诸如显示方法和基本字符串模板函数等特性. 1. 准备工作 ...

  5. jdbc数据访问技术

    jdbc数据访问技术 1.JDBC如何做事务处理? Con.setAutoCommit(false) Con.commit(); Con.rollback(); 2.写出几个在Jdbc中常用的接口 p ...

  6. 使用原生JDBC方式对数据库进行操作

    使用原生JDBC方式对数据库进行操作,包括六个步骤: 1.加载JDBC驱动程序 在连接数据库之前,首先要加载想要连接的数据库的驱动到JVM.可以通过java.lang.Class类的静态方法forNa ...

  7. SharePoint—用REST方式访问列表

    REST的定义与作用 在SharePoint 2010中,基本上有如下几种数据访问方式: 服务器端对象模型 LINQ to SharePoint Web Service 客户端对象模型 ADO.NET ...

  8. salesforce 零基础学习(三十三)通过REST方式访问外部数据以及JAVA通过rest方式访问salesforce

    本篇参考Trail教程: https://developer.salesforce.com/trailhead/force_com_dev_intermediate/apex_integration_ ...

  9. URL方式访问Hadoop的内容

    * 1.设置url支持hadoop,FsUrlStreamHandlerFactory      * 2.创建URL对象,指定访问的HDFS路径      * 3.openStream获取输入流对象, ...

随机推荐

  1. sql 索引笔记2

    以下资料都来于MSDN. 聚集索引指南: 一.此列和列值供内部使用,用户不能查看或访问. 查询注意事项 在创建聚集索引之前,应先了解数据是如何被访问的.考虑对具有以下特点的查询使用聚集索引: 使用运算 ...

  2. GMA Round 1 极坐标的愤怒

    传送门 极坐标的愤怒 我也想被积分啊!可是为什么你们从来不知道我的心意!——极坐标 愤怒会夺走理智,哪怕是被迫的也好,请为极坐标方程$r=t$(也写作$ρ=θ$)积分吧. 为了考验你的忠诚,你需要回答 ...

  3. Codeforces909C Python Indentation(动态规划)

    http://codeforces.com/problemset/problem/909/C dp[i][j]表示第i行缩进j的方案数. 当第i-1行为f时,无论当前行是f或s都必须缩进,即dp[i] ...

  4. .Net Core中的通用主机(一)——系统配置

    ASP.NET Core 2.0 中的 WebHost(实现 IWebHost 的基类)是用于为进程提供 HTTP 服务器功能的基础结构项目,例如,如果正在实现 MVC Web 应用或 Web API ...

  5. Introducing XAML Standard and .NET Standard 2.0

    XAML Standard We are pleased to announce XAML Standard, which is a standards-based effort to unify X ...

  6. ABAP技术总结

      SAP ——ABAP/4 技术总结 V3.0 2014-10-14 --江正军 1. 1.1. 1.1.1. 1.2. 1.3. 1.4. 1.5. 1.6. 1.7. 1.7.1. 1.7.2. ...

  7. Spring Boot tomcat

    定制内嵌 Tomcat 设置内嵌Tomcat的端口 Spring Boot 内嵌的 Tomcat 服务器默认运行在 8080 端口.如果,我们需要修改Tomcat的端口,我们可以在 src/main/ ...

  8. 理解Docker镜像分层

    关于base镜像 base 镜像有两层含义: 不依赖其他镜像,从 scratch 构建. 其他镜像可以之为基础进行扩展. 所以,能称作 base 镜像的通常都是各种 Linux 发行版的 Docker ...

  9. [Algorithm] Fibonacci Sequence - Anatomy of recursion and space complexity analysis

    For Fibonacci Sequence, the space complexity should be the O(logN), which is the height of tree. Che ...

  10. Love2D游戏引擎制作贪吃蛇游戏

    代码地址如下:http://www.demodashi.com/demo/15051.html Love2D游戏引擎制作贪吃蛇游戏 内附有linux下的makefile,windows下的生成方法请查 ...