首先對kylin有一個初步的瞭解。http://www.csdn.net/article/2014-10-25/2822286mysql
首先導入kylin的jdbc驅動:sql
pom文件以下apache
<dependency>
<groupId>org.apache.kylin</groupId>
<artifactId>kylin-jdbc</artifactId>
<version>1.6.0</version>
</dependency>api
建立jdbc鏈接url
Driver driver = (Driver) Class.forName("org.apache.kylin.jdbc.Driver").newInstance();
Properties info = new Properties();
info.put("user", Global.getConfig("kylin.service.username"));
info.put("password", Global.getConfig("kylin.service.password"));
Connection conn = driver.connect(String.format(Global.getConfig("kylin.jdbc.url"), proName), info);//proName---對應的立方體spa
配置文件.net
#============================#
#=========== kylin ==========#k日誌
#============================#
kylin.service.base=http://192.168.10.207:7070/kylin/
kylin.service.url=http://192.168.10.207:7070/kylin/api/
kylin.service.username=admin
kylin.service.password=KYLIN
kylin.jdbc.url=jdbc:kylin://192.168.10.201:7070/%scode
分頁獲取總記錄數:orm
select count(1) from ( select flowcode,flow_name,unit_name,rece_unit_name,sendtime,receivetime,status,date_day from T_CHANGE_SHARELOG where 1=1 group by flowcode,flow_name,unit_name,rece_unit_name,sendtime,receivetime,status,date_day )
必須group by之後再count。
分頁的時候因爲沒有像mysql的limit 1,10;
只能有limit 10;
分頁的思路就是--------和hive同樣
// 獲取第一頁數據:
// select * from table order by id asc limit
// 10;//同時須要記錄這10條中最大的id爲preId,做爲下一頁的條件。
// 獲取第二頁數據:
// select * from table where id >preId order by id asc limit
// 10;//同時保存數據中最大的id替換preId。
我這裏是按照日誌的接收時間作的排序比較,分頁的
最後比較坑的是麒麟的jdbc有個時區的問題,每條查詢出來的記錄老是和hive裏面的數據差8個小時,
所以每條記錄設置時間的時候還要加8小時
public String add8hours(SimpleDateFormat sdf,String dateString) throws ParseException { Date date = sdf.parse(dateString); Date resultime = DateUtils.addHours(date, 8); return sdf.format(resultime); }