欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

kylin 通过jdbc驱动进行sql查询

程序员文章站 2024-03-22 16:31:34
...

1、创建maven工程,添加依赖

<!-- https://mvnrepository.com/artifact/org.apache.kylin/kylin-jdbc -->
		<dependency>
			<groupId>org.apache.kylin</groupId>
			<artifactId>kylin-jdbc</artifactId>
			<version>2.2.0</version>
		</dependency>

2、编写代码

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import org.apache.kylin.jdbc.Driver;

public class Query {
	public static void main(String[] args) 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://ip:port/projectName", info);
		String sqlStr = "select distinct userid from dbName.sheetName where day_time <? limit 10000";
		PreparedStatement ps = conn.prepareStatement(sqlStr);
		ps.setString(1, "2018-02-01");
		ResultSet resultSet = ps.executeQuery();
		List uidList = new ArrayList();
		while (resultSet.next()) {
			uidList.add(resultSet.getString(1));
		}
		uidList.forEach(uid -> System.out.println(uid));
	}
}

3、查询结果

kylin 通过jdbc驱动进行sql查询

4、前期准备

在kylin下创建Project、model、cube;最好通过在web界面能够进行成功的sql查询后,再利用jdbc进行sql查询

kylin 通过jdbc驱动进行sql查询


5、参考

上一篇: 使用JDBC的方法

下一篇: kylin