Getting result data from the Database Query Browser

I'm having trouble getting the result data from the Database Query Browser. There looks to be a setter but no getter.

I got access to the query browser with

QueryBrowser queryBrowser = context.getQueryBrowserPanel();

I have a menu item with an action listener that gets the selected results table.

    menuItem.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
        ResultTable resultTable = queryBrowser.getSelectedTab();
        logger.info("Tab Name: " + resultTable.getTabName());
        logger.info("Last Query: " + resultTable.getLastQuery());
        logger.info("Index: " + Integer.toString(resultTable.getIndex()));

    }
});

Is it possible to get the result data?

1 Like

Looks like you can get the JideTable from resultTable.table, the data should be in there via getValueAt(row, column).

It looks to be protected and I get an access error when I try to compile.

The designer is mostly unenforcing if you use reflection to access that.

1 Like

2 Likes

Interesting. I'm still a bit new to Java. Do you mind pointing me to a good resource or providing a simple example on what you mean by reflection?

Class.getDeclaredField(...)

Down the rabbit hole you go....

2 Likes

:joy: I love rabbit holes. Thanks!

...

It worked!

My question is: What are you trying to do with the DB query browser from Java?

Some colleagues wanted a convenient export button feature (CSV, Spreadsheet). I know I could easily do that with a python API function or do something similar with a Perspective project, but there is no fun in that.

If you select the results you care about in the query browser and Ctrl/Cmd + Shift + C, the data will be copied to the clipboard as TSV, which pastes directly into Excel/etc as tabular data.

Not to discourage the learning exercise :slight_smile:

4 Likes