Advertisement
Guest User

Untitled

a guest
Aug 24th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. ```
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import java.sql.PreparedStatement;
  5. import java.util.Properties;
  6.  
  7. public class PhoenixPreparedStmt {
  8.  
  9. public static void main(String args[]) throws Exception {
  10. final String sql = "upsert into TBL values (?,?)";
  11. String value = null;
  12. long key = 0;
  13. Properties prop = new Properties();
  14. prop.setProperty("zookeeper.znode.parent","hbase");
  15. Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");
  16. System.out.println("getting connection");
  17. PreparedStatement stmt = null;
  18. Connection con = DriverManager.getConnection("jdbc:phoenix:localhost:2181:/hbase");
  19. System.out.println("connected: " + con.toString());
  20. stmt = con.prepareStatement(sql);
  21. for (int j = 300000; j < 400000; j+=20) {
  22. for (int i = j; i < j+20; i++) {
  23. key = i;
  24. value = "A"+i;
  25. stmt.setLong(1, key);
  26. stmt.setString(2, value);
  27. stmt.addBatch();
  28. }
  29. stmt.executeBatch();
  30. con.commit();
  31. }
  32. Thread.sleep(60000);
  33. stmt.close();
  34. con.close();
  35. }
  36. }
  37. ```
  38.  
  39. ```
  40. 0: jdbc:phoenix:localhost:2181:/hbase> !describe tbl
  41. +------------+--------------+-------------+--------------+------------+------------+--------------+----------------+-----------------+------------------+
  42. | TABLE_CAT | TABLE_SCHEM | TABLE_NAME | COLUMN_NAME | DATA_TYPE | TYPE_NAME | COLUMN_SIZE | BUFFER_LENGTH | DECIMAL_DIGITS | NUM_PREC_RADIX |
  43. +------------+--------------+-------------+--------------+------------+------------+--------------+----------------+-----------------+------------------+
  44. | | | TBL | ID | -5 | BIGINT | null | null | null | null |
  45. | | | TBL | VAL | 12 | VARCHAR | null | null | null | null |
  46. +------------+--------------+-------------+--------------+------------+------------+--------------+----------------+-----------------+------------------+
  47. 0: jdbc:phoenix:localhost:2181:/hbase>
  48. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement