关闭

通过JDBC访问ThriftServer

标签: ThriftServer
446人阅读 评论(0) 收藏 举报
分类:

通过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();
	}
}



0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:15258次
    • 积分:250
    • 等级:
    • 排名:千里之外
    • 原创:10篇
    • 转载:1篇
    • 译文:0篇
    • 评论:1条
    文章分类
    最新评论