java连接impala数据库

<span style="font-family: Arial, Helvetica, sans-serif;">package com.boco.impala;</span>


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class ImpalaJDBC {
	 private static final String SQL_STATEMENT = "select * from t_history";
	  private static final String IMPALAD_HOST = "120.132.**.161";
	  private static final String IMPALAD_JDBC_PORT = "250*3";
	  private static final String CONNECTION_URL = "jdbc:hive2://" + IMPALAD_HOST + ':' + IMPALAD_JDBC_PORT + "/dbname;auth=noSasl";
	  
	  private static final String JDBC_DRIVER_NAME = "org.apache.hive.jdbc.HiveDriver";
	  
	  public static void main(String[] args) {
	    System.out.println("\n=============================================");
	    System.out.println("Cloudera Impala JDBC Example");
	    System.out.println("Using Connection URL: " + CONNECTION_URL);
	    System.out.println("Running Query: " + SQL_STATEMENT);
	 
	    Connection con = null;
	 
	    try {
	 
	      Class.forName(JDBC_DRIVER_NAME);
	      con = DriverManager.getConnection(CONNECTION_URL);
	      System.out.println(CONNECTION_URL);
	      Statement stmt = con.createStatement();
	      ResultSet rs = stmt.executeQuery(SQL_STATEMENT);
	      System.out.println("\n== Begin Query Results ======================");
	      // print the results to the console
	      while (rs.next()) {
	        System.out.println(rs.getString(1));
	      }
	 
	      System.out.println("== End Query Results =======================\n\n");
	 
	    } catch (SQLException e) {
	      e.printStackTrace();
	    } catch (Exception e) {
	      e.printStackTrace();
	    } finally {
	      try {
	        con.close();
	      } catch (Exception e) {
	      }
	    }
	  }
}

展开阅读全文

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