code: public static String getValueClassName(StorageService storageService, DataSource ds, String sql) throws Exception {
  
          try {
              if ((sql != null) && !sql.trim().equals("")) {
                  Connection con = null;
                  try {
                      con = ConnectionUtil.createConnection(storageService, ds);
                      int index = sql.toLowerCase().indexOf("where");
                      int index2 = sql.indexOf("${");
                      String newSql = sql;
                      if ((index > 0) && (index2 > 0)) {                        
                          newSql = sql.substring(0, index) + " where 1 = 0";
                      }                    
                      QueryUtil qu = new QueryUtil(con, DialectUtil.getDialect(con));
                      List<NameType> list = qu.executeQueryForColumnNames(newSql);
                      //System.out.println("*** newType=" + list.get(0).getType());
                      return list.get(0).getType();
                  } finally {
                      ConnectionUtil.closeConnection(con);
                  }
              }
          } catch (Exception ex) {
              ex.printStackTrace();
              LOG.error(ex.getMessage(), ex);
              throw ex;
          }
          return null;
      }
docs: get value class name for the first column on a select sql query