我们如何使用Java确定Apache Phoenix中的表上是否已存在列?
Normal DB query would be this.
SELECT COUNT(*) FROM SYSTEM.CATALOG WHERE TABLE_NAME = 'TABLE_NAME' AND COLUMN_NAME = 'COL_NAME';
Checking via java (You could get this by running the above query and checking for count as well).
public static boolean doesColumnExists(String connectionStr, String tableName, String columnName)
throws SQLException {
Connection phoenixConnection = DriverManager.getConnection(connectionStr);
DatabaseMetaData databaseMetaData = phoenixConnection.getMetaData();
ResultSet colResult = databaseMetaData.getColumns("", "", tableName, columnName);
return colResult.next();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.