Yes it is possible. There are two ways by which it can be done:
1.) Using Hive JDBC connection(which you are looking for).
2.) Using HiveMetastoreClient.
Here are code snippets for the above two approaches:
First Approach:
ResultSet resultSet = .executeQuery("DESCRIBE ");
ResultSetMetaData metaData = resultSet.getMetaData();
while (resultSet.next()) {
System.out.println(" Column names : "+resultSet.getString(metaData.getColumnName(1)));
}
In this approach we need to create a resultsetmetadata object and using this object we can get the details of the query output. In your case "describe table"
Second Approach:
HiveMetaStoreClient metastoreClient = null;
HiveConf hiveConf = new HiveConf();
metastoreClient = new HiveMetaStoreClient(hiveConf);
List list = metastoreClient.getFields(,);
for (int i = 0; i < list.size(); i++) {
System.out.println("Column names : "+list.get(i).getName());
}
metastoreClient.close();
In this approach we are not running any query, we are simply connecting to the HiveMetastore and from there we are getting the details of a given table under given database.
Hope it helps...!!!