Kylin provides a standard ODBC and JDBC interface that can be well integrated with traditional BI tools. Analysts can use the tools they are most familiar with to enjoy the Kylin brought fast. We can also customize it to develop reports, etc., the Kylin as a database server on the line.
First, let's take a look at the URL format of the connection Kylin:
Jdbc:kylin://
Note:
If "SSL" is true, then the port number above should be the HTTPS port number for the Kylin service.
The kylin_project_name must be specified and exist in the Kylin service.
The operating environment needs to copy the installation file's Lib directory to its own project reference.
Here are a few ways to access Kylin data:
The first method: Query using the statement method
Second method: Query using PreparedStatement mode
Third method: Get query result set metadata
PackageOrg.apache.kylin.jdbc;Importjava.sql.SQLException;Importjava.util.Properties;Importorg.junit.Test;Importjava.sql.Connection; ImportJava.sql.Driver;Importjava.sql.PreparedStatement;ImportJava.sql.ResultSet; Importjava.sql.Statement; /** * @author: * @date: April 17, 2017 *@version1.0 * @parameter*/ Public classQuerykylinst {@Test Public voidTeststatementwithmockdata ()throwsSQLException, Instantiationexception, Illegalaccessexception, classnotfoundexception {//load the Kylin JDBC driverDriver Driver = (Driver) class.forname ("Org.apache.kylin.jdbc.Driver"). newinstance (); //Configure user name and password for login KylinProperties info=NewProperties (); Info.put ("User", "ADMIN"); Info.put ("Password", "KYLIN"); //Connecting Kylin ServicesConnection 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 voidTestanylist ()throwsException {Driver Driver= (Driver) class.forname ("Org.apache.kylin.jdbc.Driver"). newinstance (); Properties Info=NewProperties (); 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 voidTestmetadatalist ()throwsException {Driver Driver= (Driver) class.forname ("Org.apache.kylin.jdbc.Driver"). newinstance (); Properties Info=NewProperties (); 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"); //The third is the table name, which, in general, can be set directly to NULL if you want to get all the tables, and if you set a specific table name, the specific information for that table is returned. ResultSet tables = Conn.getmetadata (). Gettables (NULL,NULL,NULL,Newstring[]{"TABLE"}); while(Tables.next ()) {//for (int i = 0; i < i++) {//System.out.println (tables.getstring (i + 1)); // }String col1 = tables.getstring (1);//Table CategoryString col2 = tables.getstring (2);//Table ModeString col3 = tables.getstring (3);//Table nameSYSTEM.OUT.PRINTLN ("Table info:" +col1+ "\ T" + col2 + "\ T" +col3); } } }
The results are as follows: due to unit tests, sequencing is inconsistent, attention to neglect
Resources
Http://kylin.apache.org/docs20/howto/howto_jdbc.html
Http://www.cnblogs.com/en-heng/p/5420269.html Python Post mode
http://blog.csdn.net/linlinv3/article/details/53893144 Java uses httpclient for post access
Kylin how to access or invoke the JDBC method