当前位置:Gxlcms > 数据库问题 > Kylin如何进行JDBC方式访问或者调用

Kylin如何进行JDBC方式访问或者调用

时间:2021-07-01 10:21:17 帮助过:23人阅读

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方式访问或者调用

标签:etl   介绍   log   调用   blog   detail   情况   test   好的   

人气教程排行