String username = "";
String password = "";
String url = "jdbc:phoenix:10.1.20.129, 10.1.20.124, 10.1.20.44";
Connection connection = null;
Statement statement = null;
ResultSet set = null;
try {
Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");
connection = DriverManager.getConnection(url, username, password);
statement = connection.createStatement();
statement.execute(" create table if not exists test"
+ "(id bigint not null primary key, cf1.a bigint , cf1.b bigint, cf2.c bigint , cf2.d bigint) ");
for (int i = 10; i < 29; i++) {
statement.executeUpdate("upsert into test values (10000" + i + "," + i * 2 + "," + i * 3 + "," + i * 5 + "," + i * 7 + ")");
}
connection.commit();
set = statement.executeQuery(" select id, a, b , c , d from test ");
System.out.println("id \t a \t b \t c \t d");
while (set.next()) {
Long id = set.getLong("id");
Long a = set.getLong("a");
Long b = set.getLong("b");
Long c = set.getLong("c");
Long d = set.getLong("d");
System.out.println(id + "\t" + a + "\t" + b + "\t" + c + "\t" + d);
}
} catch (SQLException ex) {
Logger.getLogger(GetData.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(GetData.class.getName()).log(Level.SEVERE, null, ex);
} finally {
if (set != null) {
try {
set.close();
} catch (SQLException ex) {
Logger.getLogger(GetData.class.getName()).log(Level.SEVERE, null, ex);
}
}
if (statement != null) {
try {
statement.close();
} catch (SQLException ex) {
Logger.getLogger(GetData.class.getName()).log(Level.SEVERE, null, ex);
}
}
if (connection != null) {
try {
connection.close();
} catch (SQLException ex) {
Logger.getLogger(GetData.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
String password = "";
String url = "jdbc:phoenix:10.1.20.129, 10.1.20.124, 10.1.20.44";
Connection connection = null;
Statement statement = null;
ResultSet set = null;
try {
Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");
connection = DriverManager.getConnection(url, username, password);
statement = connection.createStatement();
statement.execute(" create table if not exists test"
+ "(id bigint not null primary key, cf1.a bigint , cf1.b bigint, cf2.c bigint , cf2.d bigint) ");
for (int i = 10; i < 29; i++) {
statement.executeUpdate("upsert into test values (10000" + i + "," + i * 2 + "," + i * 3 + "," + i * 5 + "," + i * 7 + ")");
}
connection.commit();
set = statement.executeQuery(" select id, a, b , c , d from test ");
System.out.println("id \t a \t b \t c \t d");
while (set.next()) {
Long id = set.getLong("id");
Long a = set.getLong("a");
Long b = set.getLong("b");
Long c = set.getLong("c");
Long d = set.getLong("d");
System.out.println(id + "\t" + a + "\t" + b + "\t" + c + "\t" + d);
}
} catch (SQLException ex) {
Logger.getLogger(GetData.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(GetData.class.getName()).log(Level.SEVERE, null, ex);
} finally {
if (set != null) {
try {
set.close();
} catch (SQLException ex) {
Logger.getLogger(GetData.class.getName()).log(Level.SEVERE, null, ex);
}
}
if (statement != null) {
try {
statement.close();
} catch (SQLException ex) {
Logger.getLogger(GetData.class.getName()).log(Level.SEVERE, null, ex);
}
}
if (connection != null) {
try {
connection.close();
} catch (SQLException ex) {
Logger.getLogger(GetData.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
打印:
id a
b c
d
1000010 20
30 50 70
1000011 22
33 55 77
1000012 24
36 60 84
1000013 26
39 65 91
1000014 28
42 70 98
1000015 30
45 75 105
1000016 32
48 80 112
1000017 34
51 85 119
1000018 36
54 90 126
1000019 38
57 95 133
1000020 40
60 100
140
1000021 42
63 105
147
1000022 44
66 110
154
1000023 46
69 115
161
1000024 48
72 120
168
1000025 50
75 125
175
1000026 52
78 130
182
1000027 54
81 135
189
1000028 56
84 140
196