Where Result set is stored while working with jdbc and oracle driver

后端 未结 4 1162
盖世英雄少女心
盖世英雄少女心 2021-01-04 09:27

Once I use jdbc with oracle driver and run select query is the result of the query is stored in the server of oracle memory or file system or temp table ?

and once I

相关标签:
4条回答
  • 2021-01-04 10:01

    After you execute the query, the data is returned to the JVM. The JVM handles all the data I/O from that point.

    0 讨论(0)
  • 2021-01-04 10:05

    A default number of rows (not the entire result set) will be fetched in your local memory. Once you reach at the last line of the fetched rows (say by doing next() and try to access next row) and if there are more rows in the result, then another round-trip call will be made to the database to fetch next batch of rows.

    EDIT 1:

    You can see how many rows your resultset is fetching at a time by doing this (please verify the syntax):

    rs.beforeFirst(); // will put cursor before the first row
    rs.last(); // will put cursor after the last line
    int noOfRows = rs.getRow(); // will give you the current row number
    

    EDIT 2:

    If you want to get more rows in the local memory than usual, you may consider CachedRowSet. Even this will make round-trips, but generally less than normal resultset. However, you should consider doing some performance checks for your applications.

    0 讨论(0)
  • 2021-01-04 10:07

    I got it from Oracle JDBC documentation:

    Fetch size

    By default, when Oracle JDBC runs a query, it retrieves a result set of 10 rows at a time from the database cursor. This is the default Oracle row fetch size value. You can change the number of rows retrieved with each trip to the database cursor by changing the row fetch size value. Standard JDBC also enables you to specify the number of rows fetched with each database round-trip for a query, and this number is referred to as the fetch size. In Oracle JDBC, the row-prefetch value is used as the default fetch size in a statement object. Setting the fetch size overrides the row-prefetch setting and affects subsequent queries run through that statement object. Fetch size is also used in a result set. When the statement object run a query, the fetch size of the statement object is passed to the result set object produced by the query. However, you can also set the fetch size in the result set object to override the statement fetch size that was passed to it.

    https://docs.oracle.com/cd/E11882_01/java.112/e16548.pdf

    p. 17-4

    0 讨论(0)
  • 2021-01-04 10:12

    Depending on the exact implementation, part of the resultset will be prefetched into the JVM and part of it will either be in the memory of the Oracle server, or will simply be loaded from the database when more rows are requested.

    When executing a query the database does not always need to read all rows from before returning data to the client (depending on the access path of the query, ability of the optimizer, functionality of the db etc).

    When you set the fetchSize() on the Statement, you are only giving a hint to the JDBC driver how much you think it should prefetch. The JDBC driver is free to ignore you. I do not know what the Oracle driver does with the fetchSize(). Most notorious AFAIK is (or maybe was) the MySQL JDBC driver which will always fetch all rows unless you set the fetchSize() to Integer.MIN_VALUE.

    0 讨论(0)
提交回复
热议问题