通过JDBC访问ThriftServer

来源:互联网 发布:超易药品进销存软件 编辑:程序博客网 时间:2024/04/29 18:05

通过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 blocke.printStackTrace();} finally {try {resultSet.close();conn.close();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}



0 0