Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. What does Statement.setFetchSize(nSize) method really do?

What does Statement.setFetchSize(nSize) method really do?

Scheduled Pinned Locked Moved Java
databasesql-serveroraclesysadminperformance
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cofi
    wrote on last edited by
    #1

    hi. i have this really big table with some millions of records every day and in the end of every day i am extracting all the records of the previous day. i am doing this like String SQL = "select col1, col2, coln from mytable where timecol = yesterday"; Statement.executeQuery(SQL); but the problem is that this program takes like 2GB of memory because it takes all the results in memory then it processes it. i tried setting the Statement.setFetchSize(10) but it takes exactly the same memory from OS it does not make any difference. i'm using "Microsoft SQL Server 2005 JDBC Driver" for this. i there any way to read the results in small chunks like oracle does when the query is executed it show only a few rows and as you scroll down more results are shown?

    N 1 Reply Last reply
    0
    • C cofi

      hi. i have this really big table with some millions of records every day and in the end of every day i am extracting all the records of the previous day. i am doing this like String SQL = "select col1, col2, coln from mytable where timecol = yesterday"; Statement.executeQuery(SQL); but the problem is that this program takes like 2GB of memory because it takes all the results in memory then it processes it. i tried setting the Statement.setFetchSize(10) but it takes exactly the same memory from OS it does not make any difference. i'm using "Microsoft SQL Server 2005 JDBC Driver" for this. i there any way to read the results in small chunks like oracle does when the query is executed it show only a few rows and as you scroll down more results are shown?

      N Offline
      N Offline
      Nagy Vilmos
      wrote on last edited by
      #2

      According to the javadoc: _Gives the JDBC driver a hint as to the number of rows that should be fetched from the database when more rows are needed for ResultSet objects genrated by this Statement. If the value specified is zero, then the hint is ignored. The default value is zero. @param rows the number of rows to fetch @exception SQLException if a database access error occurs, this method is called on a closed <code>Statement</code> or the condition rows >= 0 I think you have to set the fetch size before executing the query and it does depend on the driver implimentation and the database if the entire query is executed up front or not. I cannot tell you the level of implimentation provided by SQL Server; I'm guessing around nothing.


      Panic, Chaos, Destruction. My work here is done.

      _

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups