JDBC连接Impala

 

下载依赖包:https://downloads.cloudera.com/impala-jdbc/impala-jdbc-0.5-2.zip

 

将解压后的jar包拷贝到提供JDBC服务的Impalad node上,/usr/lib/impala/lib/

 

package impala;

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 key,bucketname FROM ddd limit 10";
	private static final String IMPALAD_HOST = "dasp06";
	private static final String IMPALAD_JDBC_PORT = "21050";
	private static final String CONNECTION_URL = "jdbc:hive2://" + IMPALAD_HOST + ':' + IMPALAD_JDBC_PORT + "/;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);
			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) {
			}
		}
	}
}

 

=============================================
Cloudera Impala JDBC Example
Using Connection URL: jdbc:hive2://dasp06:21050/;auth=noSasl
Running Query: SELECT key,bucketname FROM ddd limit 10

 

== Begin Query Results ======================
13400000064_1388056783_460095106148962
13400000144_1387531071_460606566970889
13400000176_1387214311_460437075415459
13400000384_1387015021_460869851976295
13400000471_1388065887_460594566346749
13400000592_1387018632_460687636760504
13400000838_1387181839_460737051018638
13400000878_1387741971_460459270379452
13400000883_1387740711_460129445054201
13400000895_1387244628_460053319101762
== End Query Results =======================

你可能感兴趣的:(impala,jdbc)