Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ```
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.util.Properties;
- public class PhoenixPreparedStmt {
- public static void main(String args[]) throws Exception {
- final String sql = "upsert into TBL values (?,?)";
- String value = null;
- long key = 0;
- Properties prop = new Properties();
- prop.setProperty("zookeeper.znode.parent","hbase");
- Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");
- System.out.println("getting connection");
- PreparedStatement stmt = null;
- Connection con = DriverManager.getConnection("jdbc:phoenix:localhost:2181:/hbase");
- System.out.println("connected: " + con.toString());
- stmt = con.prepareStatement(sql);
- for (int j = 300000; j < 400000; j+=20) {
- for (int i = j; i < j+20; i++) {
- key = i;
- value = "A"+i;
- stmt.setLong(1, key);
- stmt.setString(2, value);
- stmt.addBatch();
- }
- stmt.executeBatch();
- con.commit();
- }
- Thread.sleep(60000);
- stmt.close();
- con.close();
- }
- }
- ```
- ```
- 0: jdbc:phoenix:localhost:2181:/hbase> !describe tbl
- +------------+--------------+-------------+--------------+------------+------------+--------------+----------------+-----------------+------------------+
- | TABLE_CAT | TABLE_SCHEM | TABLE_NAME | COLUMN_NAME | DATA_TYPE | TYPE_NAME | COLUMN_SIZE | BUFFER_LENGTH | DECIMAL_DIGITS | NUM_PREC_RADIX |
- +------------+--------------+-------------+--------------+------------+------------+--------------+----------------+-----------------+------------------+
- | | | TBL | ID | -5 | BIGINT | null | null | null | null |
- | | | TBL | VAL | 12 | VARCHAR | null | null | null | null |
- +------------+--------------+-------------+--------------+------------+------------+--------------+----------------+-----------------+------------------+
- 0: jdbc:phoenix:localhost:2181:/hbase>
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement