`

ImpalaTest

    博客分类:
  • Java
 
阅读更多
package com.niewj.demo;

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

public class ImpalaTest {
	
	  private static final String SQL_STATEMENT = "SELECT * FROM app.app_shlx_user_report_di_cut limit 10";
	  private static final String IMPALAD_HOST = "172.xx.xx.42";
	  private static final String IMPALAD_JDBC_PORT = "21050";
	  //private static final String CONNECTION_URL = "jdbc:hive2://172.xx.xx.42:21050/cmo/app;auth=noSasl";
	  private static final String CONNECTION_URL = "jdbc:hive2://192.168.193.90:21050/cmo_app;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("conn..."+con);
		      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) {
		      }
		    }
		  }
	
	}
	
 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics