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获取输入流对象, ...
随机推荐
- JS_高程3.基本概念(4)操作符
ECMA-262用于操作数据值的操作符包括: 算术操作符 位操作符 关系操作符 相等操作符 ECMAScript操作符的不同之处在于:它能够适用于很多值,包括字符串,数字值,布尔值,甚至是对象.(在应 ...
- JAVA自学笔记11
JAVA自学笔记11 1:Eclipse的安装 2:用Eclipse写一个HelloWorld案例,最终在控制台输出你的名字 A:创建项目 B:在src目录下创建包.cn.itcast C:在cn.i ...
- web项目上传图片需要刷新文件夹才能显示
问题:上传图片到指定的目录,比如上传到项目文件夹中E:\briup\workspace\Buddhism\WebContent\userImage,但是上传呢完毕之后需要手动刷新该文件夹,网页上才能正 ...
- MUI学习02-顶部导航栏
建议:先看一下MUI注意事项 连接:http://ask.dcloud.net.cn/article/122 固定栏靠前 所谓的固定栏,也就是带有.mui-bar属性的节点,都是基于fixed定位的元 ...
- flask之基础知识点
本篇导航: 路由系统 视图函数 请求与响应 模版语法 session 蓝图(blueprint).闪现 (flash) 扩展 一.路由系统 1.可传入参数: @app.route('/user/< ...
- socket.io的websocket示例
写了一个简单的demo,直接上代码吧.用的时候注意一下版本号,可能 socket.io 的 API 有修改~ 效果图 index.html <!DOCTYPE <!DOCTYPE html ...
- opencv+python-图片文本倾斜校正
# -*- coding: UTF-8 -*- import numpy as np import cv2 ## 图片旋转 def rotate_bound(image, angle): #获取宽高 ...
- hibernate JPA 使用懒加载时代理对象
hibernate延迟加载代理对象实际对象读取方式 public static <T> T deproxy (T obj) { if (obj == null) return obj; i ...
- ionic 锁定方向 禁止横屏 orientation
安装插件 cordova-plugin-screen-orientation ionic cordova plugin add cordova-plugin-screen-orientation 添加 ...
- 机器人中的轨迹规划(Trajectory Planning )
Figure. Several possible path shapes for a single joint 五次多项式曲线(quintic polynomial) $$\theta(t)=a_0+ ...