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 Infinite Scrolling Demo
原文:http://www.sitepoint.com/jquery-infinite-scrolling-demos/ Infinite Scrolling Demo 5 Usage – HTML ...
- SpringMVC中使用JSON
前台发送: 传递JSON对象 function requestJson(){ $.ajax.({ type : "post", url : "${pageContext. ...
- .NET语言的编译过程:中间语言(IL)和即时编译器(JIT)
.NET语言的编译分为两个阶段.首先高级语言被编译成一种称作IL的中间语言,与高级语言相比,IL更像是机器语言,然而,IL却包含一些抽象概念(比如:类.异常),这也是这种语言被称为中间语言的原因.IL ...
- nvidia-smi命令输出详解
nvidia-smi命令输出如下: +-----------------------------------------------------------------------------+ | ...
- angular 2 - 003 typescript
http://www.typescriptlang.org/docs/index.html var book: string = "hellp angular 2"; var nu ...
- protobuf的简单使用
操作系统 : CentOS7.3.1611_x64 gcc版本 :4.8.5 go 版本 : go1.8.3 linux/amd64 Python 版本 : 2.7.5 libprotoc : 2.5 ...
- 【推荐】Hutool 的通用工具类库
摘自3.1.1版本作者发布原话,当时看到有点说不上的情绪,为作者的坚持.热爱点个赞. 已经想不起来是怎样结识 Hutool 的,但 Hutool 伴随几个项目的推进,获得了同事一致好评. 没经过实践和 ...
- 【centos6.6环境搭建】Github unable to access SSL connect error出错处理
问题 克隆github项目出现SSL connect error git clone https://github.com/creationix/nvm Cloning into 'nvm'... f ...
- Python学习笔录
参考:http://www.runoob.com/python3/python3-data-type.html 1. type和isinstance区别type(A()) == A, type()不会 ...
- “2014年CityEngine三维建模与设计精英培训班”——全国巡回举办
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYXJjZ2lzX2FsbA==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...