Exemplo n.º 1
0
  private ResultSet executeQuery() throws SQLException {
    ResultSet result = null;

    if (!mInitialized) {
      prepareStatement();
    }

    // Get the SQL connection
    SqlConnector sql_connector = mDataset.getSqlConnector();
    if (sql_connector != null) {
      // Count number of result
      if (mNbRows < 0) {
        setParams(mStatCount);
        ResultSet tmp = mStatCount.executeQuery();
        if (tmp.next()) {
          mNbRows = tmp.getInt(1);
        }
      }

      // Execute the query
      setParams(mStatQuery);
      result = mStatQuery.executeQuery();
    }

    return result;
  }
Exemplo n.º 2
-1
  private void prepareStatement() throws SQLException {

    // Get the SQL connection
    SqlConnector sql_connector = mDataset.getSqlConnector();
    if (sql_connector != null) {
      try {
        Connection connection = sql_connector.getConnection();
        // Check statements are still valid
        if (mStatQuery == null || mStatQuery.isClosed()) {
          // Create the query statement
          mStatQuery = connection.prepareStatement(mQuery);
          mStatQuery.setFetchSize(1000);
        }
        if (mStatCount == null || mStatCount.isClosed()) {
          // Create the count statement
          mStatCount = connection.prepareStatement("SELECT COUNT(*) FROM (" + mQuery + ")");
          mStatCount.setFetchSize(1000);
        }

      } catch (IOException e) {
        mNbRows = -1;
        Factory.getLogger().log(Level.SEVERE, e.getMessage(), e);
        close();
      }
    }

    mInitialized = true;
  }