首页 > 代码库 > SparkSQL使用之JDBC代码访问Thrift JDBC Server
SparkSQL使用之JDBC代码访问Thrift JDBC Server
启动ThriftJDBCServer:
cd $SPARK_HOME/sbinstart-thriftserver.sh &
使用jdbc访问ThriftJDBCServer代码段:
package com.luogankun.spark.sqlimport java.sql.DriverManagerimport java.sql.Connectionimport java.sql.PreparedStatement/** * JDBC代码访问Thrift JDBC Server * @author luogankun */object JdbcThriftServer { def main(args: Array[String]) { Class.forName("org.apache.hive.jdbc.HiveDriver") val conn = DriverManager.getConnection("jdbc:hive2://hadoop000:10000/default", "hadoop", "") val pstat = conn.prepareStatement("SELECT track_time, url, session_id, referer, ip, end_user_id, city_id FROM page_views WHERE city_id = -1000 limit 10") val rs = pstat.executeQuery() while (rs.next()) { println("track_time: " + rs.getString("track_time") + ", url: " + rs.getString("url") + ", session_id: " + rs.getString("session_id") + ", referer: " + rs.getString("referer") + ", ip: " + rs.getString("ip") + ", end_user_id: " + rs.getString("end_user_id") + ", city_id: " + rs.getString("city_id")) } rs.close() pstat.close() conn.close() }}
SparkSQL使用之JDBC代码访问Thrift JDBC Server
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。