Example usage for java.sql ResultSetMetaData getClass

List of usage examples for java.sql ResultSetMetaData getClass

Introduction

In this page you can find the example usage for java.sql ResultSetMetaData getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.executequery.gui.resultset.ResultSetTableModel.java

private void setMetaDataVectors(ResultSetMetaData rsmd) {

    Class<?> metaClass = rsmd.getClass();
    Method[] metaMethods = metaClass.getMethods();

    List<String> columns = null;
    List<String> rowData = null;
    List<List<String>> metaData = null;

    try {//from   w ww .j a v a2s .  c  om

        int columnCount = rsmd.getColumnCount();
        columns = new ArrayList<String>(metaMethods.length - 1);
        metaData = new ArrayList<List<String>>(columnCount);

        Object[] obj = new Object[1];
        for (int j = 1; j <= columnCount; j++) {

            obj[0] = Integer.valueOf(j);
            rowData = new ArrayList<String>(metaMethods.length - 1);
            for (int i = 0; i < metaMethods.length; i++) {

                String methodName = metaMethods[i].getName();
                if (EXCLUDES.contains(methodName)) {

                    continue;
                }

                Class<?> c = metaMethods[i].getReturnType();

                if (c.isPrimitive() || c.getName().endsWith(STRING)) {

                    if (methodName.startsWith(GET)) {

                        methodName = methodName.substring(3);
                    }

                    try {

                        Object res = metaMethods[i].invoke(rsmd, obj);

                        if (methodName.equals(COLUMN_NAME)) {

                            if (j == 1) {

                                columns.add(0, methodName);
                            }

                            rowData.add(0, objectToString(res));

                        } else {

                            if (j == 1) {

                                columns.add(methodName);
                            }

                            rowData.add(objectToString(res));

                        }

                    } catch (AbstractMethodError e) {
                    } catch (IllegalArgumentException e) {
                    } catch (IllegalAccessException e) {
                    } catch (InvocationTargetException e) {
                    }

                }

            }

            metaData.add(rowData);

        }

    } catch (SQLException e) {

        Log.debug(e.getMessage(), e);
    }

    if (metaDataTableModel == null) {

        metaDataTableModel = new ResultSetMetaDataTableModel();
    }

    metaDataTableModel.setValues(columns, metaData);
}