forked from D-Net/dnet-hadoop
Adding also an update example with the appropriate table definition
This commit is contained in:
parent
c0b509abfb
commit
0b6f302652
|
@ -27,7 +27,6 @@ public class Simple {
|
|||
String jdbcDriverName = "org.apache.hive.jdbc.HiveDriver";
|
||||
|
||||
System.out.println("\n=============================================");
|
||||
System.out.println("Cloudera Impala JDBC Example");
|
||||
System.out.println("Using Connection URL: " + connectionUrl);
|
||||
System.out.println("USing JDBC Driver " + jdbcDriverName);
|
||||
|
||||
|
@ -53,19 +52,23 @@ public class Simple {
|
|||
|
||||
System.out.println("== End Query Results =======================\n\n");
|
||||
|
||||
System.out.println("==> Drop if exists");
|
||||
// Drop table if exists
|
||||
stmt.execute("DROP TABLE IF EXISTS test_db_spyros.Persons2");
|
||||
|
||||
System.out.println("==> Create table");
|
||||
// Create table
|
||||
stmt
|
||||
.execute(
|
||||
"CREATE TABLE test_db_spyros.Persons2 (PersonID int, LastName varchar(255), FirstName varchar(255))");
|
||||
"CREATE TABLE test_db_spyros.Persons2 (personid int, lastname varchar(255), firstname varchar(255)) clustered by (personid) into 100 buckets stored as orc tblproperties('transactional'='true')");
|
||||
|
||||
System.out.println("==> Insert");
|
||||
// Insert
|
||||
stmt
|
||||
.execute(
|
||||
"INSERT INTO test_db_spyros.persons2 (personid, lastname, firstname) VALUES ('1', 'ZoupZoup', 'Spyros')");
|
||||
|
||||
System.out.println("==> Select 1 on persons2");
|
||||
// Select the inserted values
|
||||
rs = stmt.executeQuery("select personid, lastname, firstname from test_db_spyros.persons2");
|
||||
while (rs.next()) {
|
||||
|
@ -73,6 +76,20 @@ public class Simple {
|
|||
System.out.println(rs.getString(1) + " | " + rs.getString(2) + " | " + rs.getString(3));
|
||||
}
|
||||
|
||||
System.out.println("==> Update");
|
||||
// Update
|
||||
stmt
|
||||
.execute(
|
||||
"UPDATE test_db_spyros.persons2 SET lastname='ZoupZoup2', firstname='Spyros2' WHERE personid=1");
|
||||
|
||||
System.out.println("==> Select 2 on persons2");
|
||||
// Select the updated values
|
||||
rs = stmt.executeQuery("select personid, lastname, firstname from test_db_spyros.persons2");
|
||||
while (rs.next()) {
|
||||
// the example query returns one String column
|
||||
System.out.println(rs.getString(1) + " | " + rs.getString(2) + " | " + rs.getString(3));
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
System.out.println("Ex 1");
|
||||
e.printStackTrace();
|
||||
|
|
Loading…
Reference in New Issue