Example usage for java.sql Statement getMaxRows

List of usage examples for java.sql Statement getMaxRows

Introduction

In this page you can find the example usage for java.sql Statement getMaxRows.

Prototype

int getMaxRows() throws SQLException;

Source Link

Document

Retrieves the maximum number of rows that a ResultSet object produced by this Statement object can contain.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    Statement statement = null;
    String url = "jdbc:odbc:databaseName";
    String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
    String username = "guest";
    String password = "guest";
    Class.forName(driver);//from w  w w  . j  a  v  a 2  s . c o  m
    Connection connection = DriverManager.getConnection(url, username, password);
    statement = connection.createStatement();
    System.out.println("Driver          :  " + driver);

    // Put each method call in a separate try block to execute them all
    System.out.print("\nMaximum rows    :");
    int maxRows = statement.getMaxRows();
    System.out.print(maxRows == 0 ? " No limit" : " " + maxRows);

    System.out.print("\nMax field size  :");
    int maxFieldSize = statement.getMaxFieldSize();
    System.out.print(maxFieldSize == 0 ? " No limit" : " " + maxFieldSize);

    System.out.print("\nTimeout          :");
    int queryTimeout = statement.getQueryTimeout();
    System.out.print(queryTimeout == 0 ? " No limit" : " " + queryTimeout);

}

From source file:net.hydromatic.optiq.test.JdbcTest.java

/** Tests that {@link java.sql.Statement#setMaxRows(int)} is honored. */
@Test/* w w  w  .j  a v  a  2 s  . c o  m*/
public void testSetMaxRows() throws Exception {
    OptiqAssert.assertThat().with(OptiqAssert.Config.REGULAR)
            .doWithConnection(new Function1<OptiqConnection, Object>() {
                public Object apply(OptiqConnection a0) {
                    try {
                        final Statement statement = a0.createStatement();
                        try {
                            statement.setMaxRows(-1);
                            fail("expected error");
                        } catch (SQLException e) {
                            assertEquals(e.getMessage(), "illegal maxRows value: -1");
                        }
                        statement.setMaxRows(2);
                        assertEquals(2, statement.getMaxRows());
                        final ResultSet resultSet = statement.executeQuery("select * from \"hr\".\"emps\"");
                        assertTrue(resultSet.next());
                        assertTrue(resultSet.next());
                        assertFalse(resultSet.next());
                        resultSet.close();
                        statement.close();
                        return null;
                    } catch (SQLException e) {
                        throw new RuntimeException(e);
                    }
                }
            });
}

From source file:org.apache.hadoop.hive.jdbc.TestJdbcDriver.java

private void doTestSelectAll(String tableName, int maxRows, int fetchSize) throws Exception {
    boolean isPartitionTable = tableName.equals(partitionedTableName);

    Statement stmt = con.createStatement();
    if (maxRows >= 0) {
        stmt.setMaxRows(maxRows);/*from   w  w  w. jav  a  2  s. c om*/
    }
    if (fetchSize > 0) {
        stmt.setFetchSize(fetchSize);
        assertEquals(fetchSize, stmt.getFetchSize());
    }

    // JDBC says that 0 means return all, which is the default
    int expectedMaxRows = maxRows < 1 ? 0 : maxRows;

    assertNotNull("Statement is null", stmt);
    assertEquals("Statement max rows not as expected", expectedMaxRows, stmt.getMaxRows());
    assertFalse("Statement should not be closed", stmt.isClosed());

    ResultSet res;

    // run some queries
    res = stmt.executeQuery("select * from " + tableName);
    assertNotNull("ResultSet is null", res);
    assertTrue("getResultSet() not returning expected ResultSet", res == stmt.getResultSet());
    assertEquals("get update count not as expected", 0, stmt.getUpdateCount());
    int i = 0;

    ResultSetMetaData meta = res.getMetaData();
    int expectedColCount = isPartitionTable ? 3 : 2;
    assertEquals("Unexpected column count", expectedColCount, meta.getColumnCount());

    String colQualifier = ((tableName != null) && !tableName.isEmpty()) ? tableName.toLowerCase() + "." : "";
    boolean moreRow = res.next();
    while (moreRow) {
        try {
            i++;
            assertEquals(res.getInt(1), res.getInt(colQualifier + "under_col"));
            assertEquals(res.getString(1), res.getString(colQualifier + "under_col"));
            assertEquals(res.getString(2), res.getString(colQualifier + "value"));
            if (isPartitionTable) {
                assertEquals(res.getString(3), partitionedColumnValue);
                assertEquals(res.getString(3), res.getString(colQualifier + partitionedColumnName));
            }
            assertFalse("Last result value was not null", res.wasNull());
            assertNull("No warnings should be found on ResultSet", res.getWarnings());
            res.clearWarnings(); // verifying that method is supported

            // System.out.println(res.getString(1) + " " + res.getString(2));
            assertEquals("getInt and getString don't align for the same result value",
                    String.valueOf(res.getInt(1)), res.getString(1));
            assertEquals("Unexpected result found", "val_" + res.getString(1), res.getString(2));
            moreRow = res.next();
        } catch (SQLException e) {
            System.out.println(e.toString());
            e.printStackTrace();
            throw new Exception(e.toString());
        }
    }

    // supposed to get 500 rows if maxRows isn't set
    int expectedRowCount = maxRows > 0 ? maxRows : 500;
    assertEquals("Incorrect number of rows returned", expectedRowCount, i);

    // should have no more rows
    assertEquals(false, moreRow);

    assertNull("No warnings should be found on statement", stmt.getWarnings());
    stmt.clearWarnings(); // verifying that method is supported

    assertNull("No warnings should be found on connection", con.getWarnings());
    con.clearWarnings(); // verifying that method is supported

    stmt.close();
    assertTrue("Statement should be closed", stmt.isClosed());
}

From source file:org.apache.hive.jdbc.TestJdbcDriver2.java

private void doTestSelectAll(String tableName, int maxRows, int fetchSize) throws Exception {
    boolean isPartitionTable = tableName.equals(partitionedTableName);

    Statement stmt = con.createStatement();
    if (maxRows >= 0) {
        stmt.setMaxRows(maxRows);/*from  w ww.j  a  va  2  s  .  c om*/
    }
    if (fetchSize > 0) {
        stmt.setFetchSize(fetchSize);
        assertEquals(fetchSize, stmt.getFetchSize());
    }

    // JDBC says that 0 means return all, which is the default
    int expectedMaxRows = maxRows < 1 ? 0 : maxRows;

    assertNotNull("Statement is null", stmt);
    assertEquals("Statement max rows not as expected", expectedMaxRows, stmt.getMaxRows());
    assertFalse("Statement should not be closed", stmt.isClosed());

    ResultSet res;

    // run some queries
    res = stmt.executeQuery("select * from " + tableName);
    assertNotNull("ResultSet is null", res);
    assertTrue("getResultSet() not returning expected ResultSet", res == stmt.getResultSet());
    assertEquals("get update count not as expected", -1, stmt.getUpdateCount());
    int i = 0;

    ResultSetMetaData meta = res.getMetaData();
    int expectedColCount = isPartitionTable ? 3 : 2;
    assertEquals("Unexpected column count", expectedColCount, meta.getColumnCount());

    boolean moreRow = res.next();
    while (moreRow) {
        try {
            i++;
            assertEquals(res.getInt(1), res.getInt(tableName + ".under_col"));
            assertEquals(res.getInt(1), res.getInt("under_col"));
            assertEquals(res.getString(1), res.getString(tableName + ".under_col"));
            assertEquals(res.getString(1), res.getString("under_col"));
            assertEquals(res.getString(2), res.getString(tableName + ".value"));
            assertEquals(res.getString(2), res.getString("value"));
            if (isPartitionTable) {
                assertEquals(res.getString(3), partitionedColumnValue);
                assertEquals(res.getString(3), res.getString(partitionedColumnName));
                assertEquals(res.getString(3), res.getString(tableName + "." + partitionedColumnName));
            }
            assertFalse("Last result value was not null", res.wasNull());
            assertNull("No warnings should be found on ResultSet", res.getWarnings());
            res.clearWarnings(); // verifying that method is supported

            // System.out.println(res.getString(1) + " " + res.getString(2));
            assertEquals("getInt and getString don't align for the same result value",
                    String.valueOf(res.getInt(1)), res.getString(1));
            assertEquals("Unexpected result found", "val_" + res.getString(1), res.getString(2));
            moreRow = res.next();
        } catch (SQLException e) {
            System.out.println(e.toString());
            e.printStackTrace();
            throw new Exception(e.toString());
        }
    }

    // supposed to get 500 rows if maxRows isn't set
    int expectedRowCount = maxRows > 0 ? maxRows : 500;
    assertEquals("Incorrect number of rows returned", expectedRowCount, i);

    // should have no more rows
    assertEquals(false, moreRow);

    assertNull("No warnings should be found on statement", stmt.getWarnings());
    stmt.clearWarnings(); // verifying that method is supported

    assertNull("No warnings should be found on connection", con.getWarnings());
    con.clearWarnings(); // verifying that method is supported

    stmt.close();
    assertTrue("Statement should be closed", stmt.isClosed());
}

From source file:org.kuali.rice.kew.docsearch.dao.impl.DocumentSearchDAOJdbcImpl.java

@Override
public DocumentSearchResults.Builder findDocuments(final DocumentSearchGenerator documentSearchGenerator,
        final DocumentSearchCriteria criteria, final boolean criteriaModified,
        final List<RemotableAttributeField> searchFields) {
    final int maxResultCap = getMaxResultCap(criteria);
    try {//from  w  w w  . j a  va  2s. c o  m
        final JdbcTemplate template = new JdbcTemplate(dataSource);

        return template.execute(new ConnectionCallback<DocumentSearchResults.Builder>() {
            @Override
            public DocumentSearchResults.Builder doInConnection(final Connection con) throws SQLException {
                final Statement statement = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                        ResultSet.CONCUR_READ_ONLY);
                try {
                    final int fetchIterationLimit = getFetchMoreIterationLimit();
                    final int fetchLimit = fetchIterationLimit * maxResultCap;
                    statement.setFetchSize(maxResultCap + 1);
                    statement.setMaxRows(fetchLimit + 1);

                    PerformanceLogger perfLog = new PerformanceLogger();
                    String sql = documentSearchGenerator.generateSearchSql(criteria, searchFields);
                    perfLog.log("Time to generate search sql from documentSearchGenerator class: "
                            + documentSearchGenerator.getClass().getName(), true);
                    LOG.info("Executing document search with statement max rows: " + statement.getMaxRows());
                    LOG.info(
                            "Executing document search with statement fetch size: " + statement.getFetchSize());
                    perfLog = new PerformanceLogger();
                    final ResultSet rs = statement.executeQuery(sql);
                    try {
                        perfLog.log("Time to execute doc search database query.", true);
                        final Statement searchAttributeStatement = con
                                .createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
                        try {
                            return documentSearchGenerator.processResultSet(criteria, criteriaModified,
                                    searchAttributeStatement, rs, maxResultCap, fetchLimit);
                        } finally {
                            try {
                                searchAttributeStatement.close();
                            } catch (SQLException e) {
                                LOG.warn("Could not close search attribute statement.");
                            }
                        }
                    } finally {
                        try {
                            rs.close();
                        } catch (SQLException e) {
                            LOG.warn("Could not close result set.");
                        }
                    }
                } finally {
                    try {
                        statement.close();
                    } catch (SQLException e) {
                        LOG.warn("Could not close statement.");
                    }
                }
            }
        });

    } catch (DataAccessException dae) {
        String errorMsg = "DataAccessException: " + dae.getMessage();
        LOG.error("getList() " + errorMsg, dae);
        throw new RuntimeException(errorMsg, dae);
    } catch (Exception e) {
        String errorMsg = "LookupException: " + e.getMessage();
        LOG.error("getList() " + errorMsg, e);
        throw new RuntimeException(errorMsg, e);
    }
}

From source file:org.pentaho.di.core.database.Database.java

private boolean canWeSetFetchSize(Statement statement) throws SQLException {
    return databaseMeta.isFetchSizeSupported() && (statement.getMaxRows() > 0
            || databaseMeta.getDatabaseInterface() instanceof PostgreSQLDatabaseMeta
            || (databaseMeta.isMySQLVariant() && databaseMeta.isStreamingResults()));
}

From source file:us.daveread.basicquery.BasicQuery.java

/**
 * Populates model with the query results. The query executed is the
 * currently selected query in the combo-box.
 * //from   ww  w  .  j a  va 2  s. co  m
 * @param rawSqlStatement
 *          The SQL statement to execute
 * @param model
 *          The model to populate with the results
 * @param tripleFile
 *          The location to write the results to as triples.
 */
private void execute(String rawSqlStatement, ListTableModel<Object> model, File tripleFile) {
    String sqlStatement = rawSqlStatement;
    Statement stmt = null;
    ResultSet result = null;
    ResultSetMetaData meta = null;
    List<Object> rowData = null;
    int retValue = 0;
    SQLWarning warning = null;
    int[] myType;
    Object value;
    String typeName;
    String colName;
    String metaName;
    boolean hasResults = false;
    boolean hasBLOB = false;
    Date connAsk = null;
    Date connGot = null;
    Date stmtGot = null;
    Date queryStart = null;
    Date queryReady = null;
    Date queryRSFetched = null;
    Date queryRSProcessed = null;
    long rows = 0;
    int cols = 0;
    boolean hasParams = false;
    final List<StatementParameter> allParams = new ArrayList<StatementParameter>();
    List<Object> outParams = null;

    modeOfCurrentTable = whichModeValue();
    mapOfCurrentTables = new HashMap<String, String>();

    // Try to prevent incorrect selection of query type by checking
    // beginning of SQL statement for obvious stuff
    // First check "Select" and Describe query types
    if (!isOkayQueryType(getQuery().getSql())) {
        // If the query type is wrong, and the user doesn't override then
        // Get Out Of Here!
        return;
    }

    // If there were BLOB columns included in the last query the connection
    // will have been left open. Since we are executing a new query we
    // can close that old connection now.
    if (conn != null) {
        try {
            conn.close();
        } catch (Throwable any) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Error (expected) closing connection", any);
            }
        }
    }

    conn = null;

    try {
        messageOut(Resources.getString("msgExecuteQuery",
                asQuery.isSelected() ? Resources.getString("msgQuery")
                        : asDescribe.isSelected() ? Resources.getString("msgDescribe")
                                : Resources.getString("msgUpdate"),
                sqlStatement), STYLE_BOLD);
        if (poolConnect.isSelected()) {
            messageOut(Resources.getString("msgPoolStats") + " ", STYLE_SUBTLE, false);
            if (getDBPool() != null) {
                messageOut(Resources.getString("msgPoolStatsCount", getDBPool().getNumActive() + "",
                        getDBPool().getNumIdle() + ""));
                LOGGER.debug("Retrieved existing DB connection pool");
            } else {
                LOGGER.debug("No existing DB pool");
                messageOut(Resources.getString("msgPoolNone"));
            }
        }
        if (getDBPool() == null || /* conn == null */
                !((String) connectString.getEditor().getItem()).equals(lastConnection)
                || !userId.getText().equals(lastUserId)
                || !new String(password.getPassword()).equals(lastPassword)) {

            removeDBPool();

            lastConnection = (String) connectString.getEditor().getItem();
            lastUserId = userId.getText();
            lastPassword = new String(password.getPassword());

            if (poolConnect.isSelected()) {
                setupDBPool(lastConnection, lastUserId, lastPassword);
            }

            messageOut(Resources.getString("msgConnCreated", lastConnection, lastUserId), STYLE_SUBTLE);
        }
        connAsk = new java.util.Date();
        if (poolConnect.isSelected()) {
            conn = DriverManager.getConnection("jdbc:apache:commons:dbcp:" + DBPOOL_NAME);
            LOGGER.debug("Got pooled connection");
            messageOut(Resources.getString("msgGotPoolConn"), STYLE_GREEN);
        } else {
            conn = DriverManager.getConnection(lastConnection, lastUserId, lastPassword);
            LOGGER.debug("Got non-pooled connection");
            messageOut(Resources.getString("msgGotDirectConn"), STYLE_GREEN);
        }

        if (hasParams = sqlStatement.indexOf("$PARAM[") > -1) {
            sqlStatement = makeParams(sqlStatement, allParams);
        }

        connGot = new java.util.Date();

        conn.setAutoCommit(autoCommit.isSelected());
        conn.setReadOnly(readOnly.isSelected());

        if (!hasParams) {
            stmt = conn.createStatement();
        } else {
            stmt = conn.prepareCall(sqlStatement);
            setupCall((CallableStatement) stmt, allParams);
        }

        stmtGot = new java.util.Date();

        try {
            if (!maxRows.getSelectedItem().equals(Resources.getString("proNoLimit"))) {
                stmt.setMaxRows(Integer.parseInt((String) maxRows.getSelectedItem()));
                messageOut("\n" + Resources.getString("msgMaxRows", stmt.getMaxRows() + ""), STYLE_SUBTLE);
            }
        } catch (Exception any) {
            LOGGER.warn("Unable to set maximum rows", any);
            messageOut(Resources.getString("errFailSetMaxRows", (String) maxRows.getSelectedItem(),
                    any.getMessage()), STYLE_YELLOW);
        }

        if (asQuery.isSelected() || asDescribe.isSelected()) {
            queryStart = new java.util.Date();
            if (!hasParams) {
                int updateCount;

                // Execute the query synchronously
                stmt.execute(sqlStatement);
                messageOut(Resources.getString("msgQueryExecutedByDB"), STYLE_GREEN);

                // Process the query results and/or report status
                if ((updateCount = stmt.getUpdateCount()) > -1) {
                    do {
                        LOGGER.debug("Looking for results [update=" + updateCount + "]");
                        stmt.getMoreResults();
                    } while ((updateCount = stmt.getUpdateCount()) > -1);
                }
                result = stmt.getResultSet();
            } else {
                result = ((PreparedStatement) stmt).executeQuery();
            }
            queryReady = new java.util.Date();
            meta = result.getMetaData();
            cols = meta.getColumnCount();
        } else {
            queryStart = new java.util.Date();
            if (!hasParams) {
                retValue = stmt.executeUpdate(sqlStatement);
            } else {
                retValue = ((PreparedStatement) stmt).executeUpdate();
            }
            queryReady = new java.util.Date();
        }

        if (asQuery.isSelected()) {
            for (int col = 0; col < cols; ++col) {
                colName = meta.getColumnName(col + 1);
                if (colName == null || colName.trim().length() == 0) {
                    colName = Resources.getString("msgUnnamedColumn", meta.getColumnLabel(col + 1));
                }

                if (configDisplayColumnDataType.isSelected()) {
                    metaName = meta.getColumnTypeName(col + 1) + " " + meta.getColumnDisplaySize(col + 1)
                            + " (";

                    // have had oracle tables report large precision values
                    // for BLOB fields that caused exception to be thrown
                    // by getPrecision() since the value was beyond int
                    try {
                        metaName += meta.getPrecision(col + 1);
                    } catch (Exception any) {
                        metaName += "?";
                        LOGGER.warn("Unable to get column precision", any);
                    }
                    metaName += ".";
                    metaName += meta.getScale(col + 1);
                    metaName += ")";

                    colName += " [" + metaName + "]";
                }

                model.addColumn(colName);
                // Keep collection of tables used for Insert and Update Menu
                // Selections
                try {
                    mapOfCurrentTables.put(meta.getTableName(col + 1), null);
                } catch (Exception any) {
                    // Probably unimplemented method - Sybase driver
                    LOGGER.warn("Failed to obtain table name from metadata", any);
                    messageOut(Resources.getString("errFailReqTableName", any.getMessage()), STYLE_SUBTLE);
                }
            }

            rowData = new ArrayList<Object>();

            myType = new int[cols];

            for (int col = 0; col < cols; ++col) {
                typeName = meta.getColumnTypeName(col + 1).toUpperCase();
                if (typeName.equals("NUMBER")) {
                    if (meta.getScale(col + 1) > 0) {
                        myType[col] = COLUMN_DATA_TYPE_DOUBLE; // DOUBLE
                    } else if (meta.getPrecision(col + 1) <= MAX_DIGITS_FOR_INT) {
                        myType[col] = COLUMN_DATA_TYPE_INT; // INTEGER
                    } else {
                        myType[col] = COLUMN_DATA_TYPE_LONG; // LONG
                    }
                } else if (typeName.equals("LONG")) {
                    myType[col] = COLUMN_DATA_TYPE_LONG;
                } else if (typeName.equals("DATETIME")) {
                    myType[col] = COLUMN_DATA_TYPE_DATETIME; // Date/Time
                } else if (typeName.equals("DATE")) {
                    myType[col] = COLUMN_DATA_TYPE_DATE; // Date/Time
                } else if (typeName.equals("BLOB")) {
                    myType[col] = COLUMN_DATA_TYPE_BLOB;
                    hasBLOB = true;
                } else {
                    myType[col] = 0; // Default - String
                }
            }

            if (tripleFile != null) {
                try {
                    final RdbToRdf exporter = new RdbToRdf(tripleFile.getAbsolutePath(), getQuery().getSql(),
                            result);
                    exporter.run();
                    rows = exporter.getLatestNumberOfRowsExported();
                    messageOut("");
                    messageOut(Resources.getString("msgEndExportToFile"), STYLE_BOLD);
                } catch (Throwable throwable) {
                    messageOut(Resources.getString("errFailDataSave", throwable.toString()), STYLE_RED);
                    LOGGER.error("Failed to save data to triples file: " + tripleFile.getAbsolutePath(),
                            throwable);
                }
            } else if (fileLogResults.isSelected()) {
                writeDataAsCSV(sqlStatement, model, DBRESULTS_NAME, result, myType, false);
            } else {
                while (result.next()) {
                    ++rows;
                    rowData = new ArrayList<Object>();

                    for (int col = 0; col < cols; ++col) {
                        value = getResultField(result, col + 1, myType[col]);
                        rowData.add(value);
                    }

                    model.addRowFast(rowData);
                    hasResults = true;
                }
                model.updateCompleted();
            }

            queryRSProcessed = new java.util.Date();
        } else if (asDescribe.isSelected()) {
            String colLabel;

            meta = result.getMetaData();

            myType = new int[DESC_TABLE_COLUMN_COUNT];

            for (int col = 0; col < DESC_TABLE_COLUMN_COUNT; ++col) {
                switch (col) {
                case DESC_TABLE_NAME_COLUMN: // Col Name
                    colLabel = Resources.getString("proColumnName");
                    myType[col] = COLUMN_DATA_TYPE_STRING;
                    break;
                case DESC_TABLE_TYPE_COLUMN: // Col Type
                    colLabel = Resources.getString("proColumnType");
                    myType[col] = COLUMN_DATA_TYPE_STRING;
                    break;
                case DESC_TABLE_LENGTH_COLUMN: // Col Length
                    colLabel = Resources.getString("proColumnLength");
                    myType[col] = COLUMN_DATA_TYPE_INT;
                    break;
                case DESC_TABLE_PRECISION_COLUMN: // Col precision
                    colLabel = Resources.getString("proColPrecision");
                    myType[col] = COLUMN_DATA_TYPE_INT;
                    break;
                case DESC_TABLE_SCALE_COLUMN: // Col scale
                    colLabel = Resources.getString("proColScale");
                    myType[col] = COLUMN_DATA_TYPE_INT;
                    break;
                case DESC_TABLE_NULLS_OK_COLUMN: // Nulls Okay?
                    colLabel = Resources.getString("proColNullsAllowed");
                    myType[col] = COLUMN_DATA_TYPE_STRING;
                    break;
                default: // oops
                    colLabel = Resources.getString("proColUndefined");
                    break;
                }

                if (configDisplayColumnDataType.isSelected()) {
                    colLabel += " [";
                    colLabel += myType[col] == 0 ? Resources.getString("proColCharType")
                            : Resources.getString("proColNumeric");
                    colLabel += "]";
                }

                model.addColumn(colLabel);
            }

            rowData = new ArrayList<Object>();

            for (int col = 0; col < cols; ++col) {
                rowData = new ArrayList<Object>();

                for (int row = 0; row < DESC_TABLE_COLUMN_COUNT; ++row) {
                    switch (row) {
                    case DESC_TABLE_NAME_COLUMN: // Name
                        colName = meta.getColumnName(col + 1);
                        if (colName == null || colName.trim().length() == 0) {
                            colName = Resources.getString("msgUnnamedColumn", meta.getColumnLabel(col + 1));
                        }
                        value = colName;
                        break;
                    case DESC_TABLE_TYPE_COLUMN: // Type
                        value = meta.getColumnTypeName(col + 1) + " (" + meta.getColumnType(col + 1) + ")";
                        break;
                    case DESC_TABLE_LENGTH_COLUMN: // Length
                        value = new Integer(meta.getColumnDisplaySize(col + 1));
                        break;
                    case DESC_TABLE_PRECISION_COLUMN: // Precision
                        try {
                            value = new Integer(meta.getPrecision(col + 1));
                        } catch (Exception any) {
                            value = "?";
                            LOGGER.warn("Unable to obtain column precision", any);
                        }
                        break;
                    case DESC_TABLE_SCALE_COLUMN: // Scale
                        value = new Integer(meta.getScale(col + 1));
                        break;
                    case DESC_TABLE_NULLS_OK_COLUMN: // Nulls Okay?
                        value = meta.isNullable(col + 1) == ResultSetMetaData.columnNullable
                                ? Resources.getString("proYes")
                                : meta.isNullable(col + 1) == ResultSetMetaData.columnNoNulls
                                        ? Resources.getString("proNo")
                                        : Resources.getString("proUnknown");
                        break;
                    default:
                        value = null;
                        break;
                    }

                    rowData.add(value);

                    // Keep collection of tables used for Insert and Update Menu
                    // Selections
                    try {
                        mapOfCurrentTables.put(meta.getTableName(col + 1), null);
                    } catch (Exception any) {
                        // Probably unimplemented method - Sybase driver
                        LOGGER.warn("Failed to obtain table name from metadata", any);
                        messageOut(Resources.getString("errFailReqTableName", any.getMessage()), STYLE_SUBTLE);
                    }
                }
                model.addRow(rowData);
            }

            while (result.next()) {
                rows++;
                for (int col = 0; col < cols; ++col) {
                    result.getObject(col + 1);
                }
            }

            queryRSFetched = new java.util.Date();

        } else {
            messageOut("\n" + Resources.getString("msgReturnValue") + " " + retValue, STYLE_BOLD, false);
            rows = stmt.getUpdateCount();
        }

        messageOut("\n" + Resources.getString("msgRows") + " ", STYLE_NORMAL, false);
        if (rows == stmt.getMaxRows() && rows > 0) {
            messageOut("" + rows, STYLE_YELLOW);
        } else {
            messageOut("" + rows, STYLE_BOLD);
        }
        messageOut("");
    } catch (SQLException sql) {
        LOGGER.error("Error executing SQL", sql);
        messageOut(Resources.getString("errFailSQL", sql.getClass().getName(), sql.getMessage()), STYLE_RED);
        userMessage(Resources.getString("errFailSQLText", sql.getMessage()),
                Resources.getString("errFailSQLTitle"), JOptionPane.ERROR_MESSAGE);
        while ((sql = sql.getNextException()) != null) {
            LOGGER.error("Next Exception", sql);
        }
        modeOfCurrentTable = -1;
    } catch (Throwable any) {
        LOGGER.error("Error executing SQL", any);
        messageOut(Resources.getString("errFailSQL", any.getClass().getName(), any.getMessage()), STYLE_RED);
        userMessage(Resources.getString("errFailSQLText", any.getMessage()),
                Resources.getString("errFailSQLTitle"), JOptionPane.ERROR_MESSAGE);
        modeOfCurrentTable = -1;
    } finally {
        fileSaveBLOBs.setEnabled(hasBLOB);
        setExportAvailable((hasResults && model.getRowCount() > 0) || tripleFile != null);
        queryMakeInsert.setEnabled(
                modeOfCurrentTable == Query.MODE_DESCRIBE || modeOfCurrentTable == Query.MODE_QUERY);

        if (hasParams) {
            outParams = getOutParams((CallableStatement) stmt, allParams);
        }

        LOGGER.debug("Check for more results");

        try {
            int resultCount = 0;
            while (stmt.getMoreResults()) {
                int updateCount;
                ++resultCount;
                updateCount = stmt.getUpdateCount();
                LOGGER.debug("More results [" + resultCount + "][updateCount=" + updateCount + "]");
            }
        } catch (SQLException sql) {
            LOGGER.error("Failed checking for more results", sql);
            messageOut(Resources.getString("errFailAddlResults", sql.getClass().getName(), sql.getMessage()));
        }

        LOGGER.debug("No more results");

        if (result != null) {
            try {
                result.close();
                LOGGER.info("Resultset closed");
            } catch (Throwable any) {
                LOGGER.error("Unable to close resultset", any);
            }
        }

        if (stmt != null) {
            try {
                warning = stmt.getWarnings();
                while (warning != null) {
                    LOGGER.warn("Stmt Warning: " + warning.toString());
                    messageOut(Resources.getString("errStmtWarning", warning.toString()), STYLE_YELLOW);
                    warning = warning.getNextWarning();
                }
            } catch (Throwable any) {
                LOGGER.warn("Error retrieving statement SQL warnings", any);
            }

            try {
                stmt.close();
                LOGGER.debug("Statement closed");
            } catch (Throwable any) {
                LOGGER.error("Unable to close statement", any);
            }
        }

        if (conn != null) {
            try {
                warning = conn.getWarnings();
                while (warning != null) {
                    LOGGER.warn("Connt Warning: " + warning.toString());
                    messageOut(Resources.getString("errConnWarning", warning.toString()), STYLE_YELLOW);
                    warning = warning.getNextWarning();
                }
            } catch (Throwable any) {
                LOGGER.warn("Error retrieving connection SQL warnings", any);
            }
        }

        // Close the connection if there are no BLOBs.
        // If the user decides to save a BLOB we will need to DB connection
        // to remain open, hence we only close here if there are no BLOBs
        if (!hasBLOB && conn != null) {
            try {
                conn.close();
                conn = null;
                LOGGER.debug("DB Connection closed");
            } catch (Throwable any) {
                LOGGER.error("Unable to close DB connection", any);
            }
        }

        reportStats(sqlStatement, connAsk, connGot, stmtGot, queryStart, queryReady, queryRSFetched,
                queryRSProcessed, rows, cols, asDescribe.isSelected() ? model : null, outParams);
        // reportResults(SQL, model);
    }
}