afreechart/src/main/java/org/afree/data/jdbc/JDBCPieDataset.java
/**
     *  ExecuteQuery will attempt execute the query passed to it against the
     *  existing database connection.  If no connection exists then no action
     *  is taken.
     *  The results from the query are extracted and cached locally, thus
     *  applying an upper limit on how many rows can be retrieved successfully.
     *
     * @param  query  the query to be executed
     * @param  con  the connection the query is to be executed against
     *
     * @throws SQLException if there is a problem executing the query.
     */
ExecuteQuery will attempt execute the query passed to it against the
existing database connection.  If no connection exists then no action
is taken.
The results from the query are extracted and cached locally, thus
applying an upper limit on how many rows can be retrieved successfully.

@param  query  the query to be executed
@param  con  the connection the query is to be executed against

@throws SQLException if there is a problem executing the query.
ExecuteQuery will attempt execute the query passed to it against the existing database connection . If no connection exists then no action is taken . The results from the query are extracted and cached locally thus applying an upper limit on how many rows can be retrieved successfully . @param query the query to be executed @param con the connection the query is to be executed against @throws SQLException if there is a problem executing the query .
public void executeQuery(Connection con, String query) throws SQLException {
        Statement statement = null;
        ResultSet resultSet = null;
        try {
            statement = con.createStatement();
            resultSet = statement.executeQuery(query);
            ResultSetMetaData metaData = resultSet.getMetaData();
            int columnCount;
            if (metaData != null) {
                columnCount = metaData.getColumnCount();
            } else {
                columnCount = 2;
            }
            if (columnCount != 2) {
                throw new SQLException(
                    "Invalid sql generated.  PieDataSet requires 2 columns only"
                );
            }
            int columnType;
            if (metaData != null) {
                columnType = metaData.getColumnType(2);
            } else {
                columnType = Types.REAL;
            }
            double value = Double.NaN;
            while (resultSet.next()) {
                Comparable key = resultSet.getString(1);
                switch (columnType) {
                    case Types.NUMERIC:
                    case Types.REAL:
                    case Types.INTEGER:
                    case Types.DOUBLE:
                    case Types.FLOAT:
                    case Types.DECIMAL:
                    case Types.BIGINT:
                        value = resultSet.getDouble(2);
                        setValue(key, value);
                        break;
                    case Types.DATE:
                    case Types.TIME:
                    case Types.TIMESTAMP:
                        Timestamp date = resultSet.getTimestamp(2);
                        value = date.getTime();
                        setValue(key, value);
                        break;
                    default:
                        System.err.println(
                            "JDBCPieDataset - unknown data type"
                        );
                        break;
                }
            }
            fireDatasetChanged();
        }
        finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                }
                catch (Exception e) {
                    System.err.println("JDBCPieDataset: swallowing exception.");
                }
            }
            if (statement != null) {
                try {
                    statement.close();
                }
                catch (Exception e) {
                    System.err.println("JDBCPieDataset: swallowing exception.");
                }
            }
        }
    }
public void executeQuery ( Connection con , String query ) throws SQLException { Statement statement = null ; ResultSet resultSet = null ; try { statement = con . createStatement ( ) ; resultSet = statement . executeQuery ( query ) ; ResultSetMetaData metaData = resultSet . getMetaData ( ) ; int columnCount ; if ( metaData != null ) { columnCount = metaData . getColumnCount ( ) ; } else { columnCount = 2 ; } if ( columnCount != 2 ) { throw new SQLException ( "Invalid sql generated.  PieDataSet requires 2 columns only" ) ; } int columnType ; if ( metaData != null ) { columnType = metaData . getColumnType ( 2 ) ; } else { columnType = Types . REAL ; } double value = Double . NaN ; while ( resultSet . next ( ) ) { Comparable key = resultSet . getString ( 1 ) ; switch ( columnType ) { case Types . NUMERIC : case Types . REAL : case Types . INTEGER : case Types . DOUBLE : case Types . FLOAT : case Types . DECIMAL : case Types . BIGINT : value = resultSet . getDouble ( 2 ) ; setValue ( key , value ) ; break ; case Types . DATE : case Types . TIME : case Types . TIMESTAMP : Timestamp date = resultSet . getTimestamp ( 2 ) ; value = date . getTime ( ) ; setValue ( key , value ) ; break ; default : System . err . println ( "JDBCPieDataset - unknown data type" ) ; break ; } } fireDatasetChanged ( ) ; } finally { if ( resultSet != null ) { try { resultSet . close ( ) ; } catch ( Exception e ) { System . err . println ( "JDBCPieDataset: swallowing exception." ) ; } } if ( statement != null ) { try { statement . close ( ) ; } catch ( Exception e ) { System . err . println ( "JDBCPieDataset: swallowing exception." ) ; } } } }
ExecuteQuery will attempt execute the query passed to it against the
  existing database connection.
ExecuteQuery will attempt execute the query passed to it against the existing database connection .