- 1.常见项目及名称
- 2.导入依赖
<dependencies>
<dependency>
<groupId>org.apache.kylin</groupId>
<artifactId>kylin-jdbc</artifactId>
<version>2.5.1</version>
</dependency>
</dependencies>
- 3. 创建测试类 TestJDBC
package com.bigdata.kylin;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
/**
* @author 卜温不火
* @create 2020-05-21 19:28
* com.bigdata.kylin - the name of the target package where the new class or interface will be created.
* kylinjdbc0521 - the name of the current project.
*/
public class TestJDBC {
public static void main(String[] args) throws Exception {
//Kylin_JDBC 驱动
String KYLIN_DRIVER = "org.apache.kylin.jdbc.Driver";
//Kylin_URL
String KYLIN_URL = "jdbc:kylin://hadoop002:7070/emp_project";
//Kylin的用户名
String KYLIN_USER = "ADMIN";
//Kylin的密码
String KYLIN_PASSWD = "KYLIN";
//添加驱动信息
Class.forName(KYLIN_DRIVER);
//获取连接
Connection connection = DriverManager.getConnection(KYLIN_URL, KYLIN_USER, KYLIN_PASSWD);
//预编译SQL
PreparedStatement ps = connection.prepareStatement("SELECT sum(sal) FROM emp group by deptno");
//执行查询
ResultSet resultSet = ps.executeQuery();
//遍历打印
while (resultSet.next()) {
System.out.println(resultSet.getInt(1));
}
}
}
- 4. 在Kylin上查看数据
select dept.dname,sum(emp.sal) from emp join dept on emp.deptno = dept.deptno group by dept.dname;
- 5. 通过TestJDBC查看数据
可以发现与在页面上进行查询返回的结果是一样的,说明我们使用JDBC连接操作Kylin就成功了。
本次的分享就到这里了