麒麟

成就一番伟业的唯一途径就是热爱自己的事业

通过JDBC访问ThriftServer

通过JDBC访问Thrift Server,进而访问Spark SQL,进而访问Hive


String sql = "select name from test where age = ?";
		String sql = "select name from test where age = ?";
Connection conn = null;
ResultSet resultSet = null;
try {
	Class.forName("org.apache.hive.jdbc.HiveDriver");
	conn = DriverManager.getConnection("jdbc:hive2://DaShuJu-040:10000/hive?"
			+ "hive.server2.transport.mode=http;hive.server2.thrift.http.path=cliservice",
			"root", "");
	
	PreparedStatement preparedStatement = conn.prepareStatement(sql);
	preparedStatement.setInt(1,30);
	
	resultSet = preparedStatement.executeQuery();
	
	while(resultSet.next()){
		System.out.println(resultSet.getString(1));//此处的数据应该保存在Parquet中等
	}
	
} catch (Exception e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
} finally {
	try {
		resultSet.close();
		conn.close();
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}



阅读更多
文章标签: ThriftServer
个人分类: SparkSQL
上一篇Scala类型系统编程
下一篇logstash读取kafka数据插件
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭