2

I am trying to get Preview(data) of a table by querying using jdbc DatabaseMetadata and ResultSet.

Below code works perfectly fine if I run it against MySQL database and returns table name as well as data correctly, but it gives EMPTY tableName if ran against Exasol database. I need help to get tableName for given resultset.

        Preview preview = new Preview();
        List<Map<String, String>> headers = new ArrayList();
        List<Map<String, String>> data = new ArrayList();
        HashMap<String, String> resultMap = new HashMap();

        PreparedStatement ps = null;
        ResultSet rs = null;
        try{
            ps = con.prepareStatement(query);

            rs = ps.executeQuery();

            ResultSetMetaData rsmd = rs.getMetaData();
            int columnCount = rsmd.getColumnCount();

            while(rs.next()) {
                HashMap<String, String> columns = new HashMap();
                Map<String, String> dataMap = new HashMap();
                headers.clear();

                for(int i = 1; i <= columnCount; ++i) {
                    Map<String, String> headersMap = new HashMap();
                    String name = rsmd.getColumnLabel(i);
                    preview.setName(rsmd.getTableName(i));
                    headersMap.put("id", name);
                    headersMap.put("name", name);
                    headersMap.put("dataType", (Object)null);
                    dataMap.put(name, rs.getObject(name) != null ? rs.getObject(name).toString() : null);
                    columns.put(name, rs.getObject(name) != null ? rs.getObject(name).toString() : null);
                    headers.add(headersMap);
                }

                data.add(dataMap);
            }
     }catch(Exception e){}

In case of exasol data is also getting returned only table name is getting as "". Any help or clue to solve this problem pls.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • 2
    Seems to me that the Exasol JDBC driver is not fully implemented, and that's not rare. I've worked with 10 databases (so far) and rarely any of them implements the full set of metadata. You are out of luck with the driver. Worst of all, it's unlikely the company will improve it, since pretty much no one uses that functionality. It's probably you and another guy, in Germany, and that's it; not much of a market segment, sorry. – The Impaler Mar 04 '20 at 14:07
  • The code as shown is the way _"to fetch table name using Jdbc from ResultSetMetaData"_. If it doesn't work, you should file a bug report with Exasol. – Mark Rotteveel Mar 04 '20 at 17:38

0 Answers0