|
1 |
| -package com.wugui.datax.admin.tool.query; |
2 |
| - |
3 |
| - |
4 |
| -import com.wugui.datax.admin.util.ReflectionUtil; |
5 |
| -import org.apache.phoenix.compile.ColumnProjector; |
6 |
| -import org.apache.phoenix.compile.RowProjector; |
7 |
| -import org.apache.phoenix.util.SchemaUtil; |
8 |
| -import sqlline.SqlLine; |
9 |
| -import org.apache.phoenix.jdbc.PhoenixDriver; |
10 |
| -import java.io.IOException; |
11 |
| -import java.sql.*; |
12 |
| -import java.util.List; |
13 |
| -import java.util.Properties; |
14 |
| - |
15 |
| -public class Hbase11xsqlToolTest { |
16 |
| - |
17 |
| - public static void main(String[] args) throws Exception { |
18 |
| - String connectionString="jdbc:phoenix:hadoop1,hadoop2,hadoop3:2181"; |
19 |
| -// String tableName = "SYSTEM.CATALOG"; |
20 |
| - String tableName = "STOCK_SYMBOL"; |
21 |
| - |
22 |
| -// getPColumns(connectionString,tableName); |
23 |
| - |
24 |
| - |
25 |
| - showTables(connectionString); |
26 |
| - |
27 |
| - getColumns(connectionString,tableName); |
28 |
| - |
29 |
| -// showFields(connectionString,null); |
30 |
| - } |
31 |
| - |
32 |
| - |
33 |
| - private static int getSize(ResultSet rs) { |
34 |
| - try { |
35 |
| - if (rs.getType() == ResultSet.TYPE_FORWARD_ONLY) { |
36 |
| - return -1; |
37 |
| - } |
38 |
| - |
39 |
| - rs.last(); |
40 |
| - int total = rs.getRow(); |
41 |
| - rs.beforeFirst(); |
42 |
| - return total; |
43 |
| - } catch (SQLException sqle) { |
44 |
| - return -1; |
45 |
| - } catch (AbstractMethodError ame) { |
46 |
| - return -1; |
47 |
| - } |
48 |
| - } |
49 |
| - |
50 |
| - |
51 |
| - |
52 |
| - private static void getColumns(String connectionString, String tableName) throws SQLException { |
53 |
| - Connection conn = DriverManager.getConnection(connectionString); |
54 |
| - DatabaseMetaData metaData = conn.getMetaData(); |
55 |
| - ResultSet columns = metaData.getColumns(conn.getCatalog(), null, tableName, "%"); |
56 |
| - |
57 |
| - |
58 |
| - try { |
59 |
| - int total = getSize(columns); |
60 |
| - int index = 0; |
61 |
| - |
62 |
| - while (columns.next()) { |
63 |
| - |
64 |
| - System.out.println(columns.getString("COLUMN_NAME")+" "+columns.getString("TYPE_NAME")); |
65 |
| - } |
66 |
| - |
67 |
| - } finally { |
68 |
| - columns.close(); |
69 |
| - } |
70 |
| - |
71 |
| - |
72 |
| - } |
73 |
| - |
74 |
| - |
75 |
| - |
76 |
| - |
77 |
| - // 查询所有的表 |
78 |
| - private static void showTables(String connectionString) throws SQLException, IOException { |
79 |
| - Connection conn = DriverManager.getConnection(connectionString); |
80 |
| - DatabaseMetaData metaData = conn.getMetaData(); |
81 |
| - ResultSet rs = metaData.getTables(conn.getCatalog(), null, "%", new String[] {"TABLE"}); |
82 |
| - |
83 |
| - try { |
84 |
| - while (rs.next()) { |
85 |
| - System.out.println(rs.getString("TABLE_NAME")); |
86 |
| - } |
87 |
| - } finally { |
88 |
| - try { |
89 |
| - rs.close(); |
90 |
| - } catch (Exception e) { |
91 |
| - } |
92 |
| - } |
93 |
| - |
94 |
| - } |
95 |
| - |
96 |
| - |
97 |
| - // 查询所有的表 |
98 |
| - private static void showFields(String connectionString,String tableName) throws SQLException, NoSuchFieldException, IllegalAccessException { |
99 |
| - |
100 |
| - Connection conn = DriverManager.getConnection(connectionString); |
101 |
| - |
102 |
| - |
103 |
| - |
104 |
| - Statement stat = conn.createStatement(); |
105 |
| - ResultSet rs = stat.executeQuery("select * from LKY_STOCK_SYMBOL limit 1"); |
106 |
| - RowProjector row = (RowProjector) ReflectionUtil.getPrivateField(rs, "rowProjector"); |
107 |
| - List<? extends ColumnProjector> column = row.getColumnProjectors(); |
108 |
| - |
109 |
| - for (int i = 0; i < column.size(); i++) { |
110 |
| - ColumnProjector columnProjector = column.get(i); |
111 |
| - System.out.println("这是字段信息 ====>" + column.get(i).getName()); |
112 |
| - //arry[i] = column.get(i).getName(); |
113 |
| - } |
114 |
| - stat.close(); |
115 |
| - conn.close(); |
116 |
| - } |
117 |
| - |
118 |
| -} |
| 1 | +//package com.wugui.datax.admin.tool.query; |
| 2 | +// |
| 3 | +// |
| 4 | +//import com.wugui.datax.admin.util.ReflectionUtil; |
| 5 | +//import org.apache.phoenix.compile.ColumnProjector; |
| 6 | +//import org.apache.phoenix.compile.RowProjector; |
| 7 | +//import org.apache.phoenix.util.SchemaUtil; |
| 8 | +//import sqlline.SqlLine; |
| 9 | +//import org.apache.phoenix.jdbc.PhoenixDriver; |
| 10 | +//import java.io.IOException; |
| 11 | +//import java.sql.*; |
| 12 | +//import java.util.List; |
| 13 | +//import java.util.Properties; |
| 14 | +// |
| 15 | +//public class Hbase11xsqlToolTest { |
| 16 | +// |
| 17 | +// public static void main(String[] args) throws Exception { |
| 18 | +// String connectionString="jdbc:phoenix:hadoop1,hadoop2,hadoop3:2181"; |
| 19 | +//// String tableName = "SYSTEM.CATALOG"; |
| 20 | +// String tableName = "STOCK_SYMBOL"; |
| 21 | +// |
| 22 | +//// getPColumns(connectionString,tableName); |
| 23 | +// |
| 24 | +// |
| 25 | +// showTables(connectionString); |
| 26 | +// |
| 27 | +// getColumns(connectionString,tableName); |
| 28 | +// |
| 29 | +//// showFields(connectionString,null); |
| 30 | +// } |
| 31 | +// |
| 32 | +// |
| 33 | +// private static int getSize(ResultSet rs) { |
| 34 | +// try { |
| 35 | +// if (rs.getType() == ResultSet.TYPE_FORWARD_ONLY) { |
| 36 | +// return -1; |
| 37 | +// } |
| 38 | +// |
| 39 | +// rs.last(); |
| 40 | +// int total = rs.getRow(); |
| 41 | +// rs.beforeFirst(); |
| 42 | +// return total; |
| 43 | +// } catch (SQLException sqle) { |
| 44 | +// return -1; |
| 45 | +// } catch (AbstractMethodError ame) { |
| 46 | +// return -1; |
| 47 | +// } |
| 48 | +// } |
| 49 | +// |
| 50 | +// |
| 51 | +// |
| 52 | +// private static void getColumns(String connectionString, String tableName) throws SQLException { |
| 53 | +// Connection conn = DriverManager.getConnection(connectionString); |
| 54 | +// DatabaseMetaData metaData = conn.getMetaData(); |
| 55 | +// ResultSet columns = metaData.getColumns(conn.getCatalog(), null, tableName, "%"); |
| 56 | +// |
| 57 | +// |
| 58 | +// try { |
| 59 | +// int total = getSize(columns); |
| 60 | +// int index = 0; |
| 61 | +// |
| 62 | +// while (columns.next()) { |
| 63 | +// |
| 64 | +// System.out.println(columns.getString("COLUMN_NAME")+" "+columns.getString("TYPE_NAME")); |
| 65 | +// } |
| 66 | +// |
| 67 | +// } finally { |
| 68 | +// columns.close(); |
| 69 | +// } |
| 70 | +// |
| 71 | +// |
| 72 | +// } |
| 73 | +// |
| 74 | +// |
| 75 | +// |
| 76 | +// |
| 77 | +// // 查询所有的表 |
| 78 | +// private static void showTables(String connectionString) throws SQLException, IOException { |
| 79 | +// Connection conn = DriverManager.getConnection(connectionString); |
| 80 | +// DatabaseMetaData metaData = conn.getMetaData(); |
| 81 | +// ResultSet rs = metaData.getTables(conn.getCatalog(), null, "%", new String[] {"TABLE"}); |
| 82 | +// |
| 83 | +// try { |
| 84 | +// while (rs.next()) { |
| 85 | +// System.out.println(rs.getString("TABLE_NAME")); |
| 86 | +// } |
| 87 | +// } finally { |
| 88 | +// try { |
| 89 | +// rs.close(); |
| 90 | +// } catch (Exception e) { |
| 91 | +// } |
| 92 | +// } |
| 93 | +// |
| 94 | +// } |
| 95 | +// |
| 96 | +// |
| 97 | +// // 查询所有的表 |
| 98 | +// private static void showFields(String connectionString,String tableName) throws SQLException, NoSuchFieldException, IllegalAccessException { |
| 99 | +// |
| 100 | +// Connection conn = DriverManager.getConnection(connectionString); |
| 101 | +// |
| 102 | +// |
| 103 | +// |
| 104 | +// Statement stat = conn.createStatement(); |
| 105 | +// ResultSet rs = stat.executeQuery("select * from LKY_STOCK_SYMBOL limit 1"); |
| 106 | +// RowProjector row = (RowProjector) ReflectionUtil.getPrivateField(rs, "rowProjector"); |
| 107 | +// List<? extends ColumnProjector> column = row.getColumnProjectors(); |
| 108 | +// |
| 109 | +// for (int i = 0; i < column.size(); i++) { |
| 110 | +// ColumnProjector columnProjector = column.get(i); |
| 111 | +// System.out.println("这是字段信息 ====>" + column.get(i).getName()); |
| 112 | +// //arry[i] = column.get(i).getName(); |
| 113 | +// } |
| 114 | +// stat.close(); |
| 115 | +// conn.close(); |
| 116 | +// } |
| 117 | +// |
| 118 | +//} |
0 commit comments