Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Default port is 21050.

 

Init Connection

 

Code Block
languagejava
// Set JDBC Impala Driver
Class.forName(JDBC_DRIVER_NAME);
// Connect to Impala - Choose a user that has the rights to write into /user/hive/warehouse/
con = DriverManager.getConnection(connectionUrl,"hdfs","");
// Init Statement
Statement stmt = con.createStatement();

 

How to create an Impala table with Java?

 

Code Block
languagejava
String sqlStatementInvalidate = "INVALIDATE METADATA";
String sqlStatementDrop = "DROP TABLE IF EXISTS helloworld";
String sqlStatementCreate = "CREATE TABLE helloworld (message String) STORED AS PARQUET";

// Invalidate metadata to update changes
stmt.execute(sqlStatementInvalidate);

// Execute DROP TABLE Query
stmt.execute(sqlStatementDrop);
// Execute CREATE Query
stmt.execute(sqlStatementCreate);
 

How to insert data into an Impala table with Java?

 

Code Block
languagejava
String sqlStatementInsert = "INSERT INTO helloworld VALUES (\"helloworld\")";
// Execute INSERT Query
stmt.execute(sqlStatementInsert);

 

How to select data from an Impala table with Java?

 

Code Block
languagejava
String sqlStatementSelect = "SELECT * from helloworld";
// Execute SELECT Query
ResultSet rs = stmt.executeQuery(sqlStatementSelect);
// Process results
while(rs.next()) {
   logger.info(rs.getString(1));
}
// Invalidate metadata to update changes
stmt.execute(sqlStatementInvalidate);