Kylin如何进行JDBC方式访问或者调用
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方式访问或者调用的更多相关文章
- 2017.11.12 web中JDBC 方式访问数据库的技术
JavaWeb------ 第四章 JDBC数据库访问技术 在JavaWeb应用程序中数据库访问是通过Java数据库连接(JavaDateBase Connectivity简称JDBC)数据库的链接一 ...
- Impala通过JDBC方式访问
不多说,直接上干货! • 配置: – impala.driver=org.apache.hive.jdbc.HiveDriver – impala.url=jdbc:hive2://node2:210 ...
- 使用jdbc的方式访问kylin cube的数据
使用jdbc的方式访问kylin cube的数据 引用kylin相关的jar包 <dependency> <groupId>org.apache.kylin</group ...
- Spring04-SpringEL&Spring JDBC数据访问
一. SpringEL入门 Spring动态语言(简称SpEL) 是一个支持运行时查询和操作对象图的强大的动态语言,语法类似于EL表达式,具有诸如显示方法和基本字符串模板函数等特性. 1. 准备工作 ...
- jdbc数据访问技术
jdbc数据访问技术 1.JDBC如何做事务处理? Con.setAutoCommit(false) Con.commit(); Con.rollback(); 2.写出几个在Jdbc中常用的接口 p ...
- 使用原生JDBC方式对数据库进行操作
使用原生JDBC方式对数据库进行操作,包括六个步骤: 1.加载JDBC驱动程序 在连接数据库之前,首先要加载想要连接的数据库的驱动到JVM.可以通过java.lang.Class类的静态方法forNa ...
- SharePoint—用REST方式访问列表
REST的定义与作用 在SharePoint 2010中,基本上有如下几种数据访问方式: 服务器端对象模型 LINQ to SharePoint Web Service 客户端对象模型 ADO.NET ...
- salesforce 零基础学习(三十三)通过REST方式访问外部数据以及JAVA通过rest方式访问salesforce
本篇参考Trail教程: https://developer.salesforce.com/trailhead/force_com_dev_intermediate/apex_integration_ ...
- URL方式访问Hadoop的内容
* 1.设置url支持hadoop,FsUrlStreamHandlerFactory * 2.创建URL对象,指定访问的HDFS路径 * 3.openStream获取输入流对象, ...
随机推荐
- poj1064 Cable master(二分查找,精度)
https://vjudge.net/problem/POJ-1064 二分就相当于不停地折半试. C++AC,G++WA不知为何,有人说C函数ans那里爆int了,改了之后也没什么用. #inclu ...
- ReactRouter升级 v2 to v4
概述 react-router V4 相对于react-router V2 or V3 几乎是重写了, 新版的react-router更偏向于组件化(everything is component). ...
- 搜狗拼音输入法 V9.1.0.2589 最新去广告精简优化版
搜狗拼音输入法9.0 正式版例行发布,最新版字母代号b,详细版本号为v9.1.0.2589:搜狗拼音输入法是电脑装机必备软件,版本有传统版和智慧版之分,其打字超准.词库超大.速度飞快.外观漂亮,因此使 ...
- Logical Volume Manager (LVM)
LVM 是一种可用在Linux内核的逻辑分卷管理器:可用于管理磁盘驱动器或其他类似的大容量存储设备. 本文提供如何在 Arch Linux 中配置和使用 Logical Volume Manager ...
- VUE温习:style层次分析
一.vue样式style层次分析 1.样式可以在main.js.模块js文件.组件style.组件script标签内,index.html文件内引入,不同位置引入的样式有什么关系. 2.总结: (1) ...
- DockerSwarm获取Token与常用命令
一.Token相关 Join tokens是允许一个节点加入集群的密钥.有两种可用的不同的join tokens,一个是用作worker角色,另一个是用作manager角色.在执行swarm join ...
- Mybatis中使用集合、数组
一.简述 本文讲Mybatis中如何将传入参数为数组或者集合对象,进行遍历,组合Where条件中如in条件等内容. 有3种情况: 如果传入的是单参数且参数类型是一个List的时候,collection ...
- Linux命令行烧录树莓派镜像至SD卡
首先下载镜像压缩包 验证压缩包的未被串改 1 sha1sum 2013-09-25-wheezy-raspbian.zip 对此命令的输出结果和官网给出的SHA-1 Checksum进行比对,如果一致 ...
- Jenkins持续集成 入门实践
本文测试环境: ASP.NET MVC项目,Windows 7环境,SVN代码仓库, MSBuild,TortoiseSVN 持续集成这种工具很多了,Jenkins比较常用,他的原理就是一个服务,有一 ...
- WCF Restful Service Get / Post请求
Rest 它是用于创建分布式超文本媒体的一种架构方式,我们可以通过标准的HTTP(GET,POST,PUT,DELETE)操作来构建基于面向资源的软件架构方式(Resource-Oriented Ar ...