在实际工作当中,因为impala的查询比较快,所以可能有会使用到impala来做数据库查询的情况,可以通过java代码来进行操作impala的查询
下载impala jdbc依赖
下载路径:
https://www.cloudera.com/downloads/connectors/impala/jdbc/2-5-28.html
因为cloudera属于商业公司性质,其提供的jar并不会出现在开源的maven仓库中,如果在企业中需要使用,请添加到企业maven私服。
创建java工程
创建普通java工程,把依赖添加工程。
java api
public static void test(){ Connection con = null; ResultSet rs = null; PreparedStatement ps = null; String JDBC_DRIVER = "com.cloudera.impala.jdbc41.Driver"; String CONNECTION_URL = "jdbc:impala://node-3:21050"; try { Class.forName(JDBC_DRIVER); con = (Connection) DriverManager.getConnection(CONNECTION_URL); ps = con.prepareStatement("select * from my_db.employee;"); rs = ps.executeQuery(); while (rs.next()) { System.out.println(rs.getString(1)); System.out.println(rs.getString(2)); System.out.println(rs.getString(3)); } } catch (Exception e) { e.printStackTrace(); } finally { try { rs.close(); ps.close(); con.close(); } catch (SQLException e) { e.printStackTrace(); } } } public static void main(String[] args) { test(); } |