In practical work, because impala queries faster, so there may be use to do database queries situation impala, impala can be operated through java code query
Download Impala jdbc dependent
Download Path:
https://www.cloudera.com/downloads/connectors/impala/jdbc/2-5-28.html
Because cloudera a commercial nature of the company, jar it provides and will not appear on the open source maven repository, if needed in an enterprise, add to corporate maven PW.
Create a java project
Creating ordinary java project, the project relies added.
java fire
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(); } |