Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8300641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:38:14+00:00 2026-06-08T16:38:14+00:00

How PreparedStatement.executeQuery works? Does it fetch results from database and I loop through them?

  • 0

How PreparedStatement.executeQuery works? Does it fetch results from database and I loop through them? Or it fetches the first result, and on record.next continues with sql query to the next row?

ResultSet record = statement.executeQuery("select * from users");
    while (record.next()) {
    //do something
}

thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T16:38:15+00:00Added an answer on June 8, 2026 at 4:38 pm

    From the documentation:

    Statement

    public ResultSet executeQuery(String sql) throws SQLException
    

    Executes the given SQL statement, which returns a single ResultSet
    object.

    ResultSet

    A table of data representing a database result set, which is usually
    generated by executing a statement that queries the database.

    public boolean next() throws SQLException
    

    Moves the cursor down one row from its current position. A ResultSet
    cursor is initially positioned before the first row; the first call to
    the method next makes the first row the current row; the second call
    makes the second row the current row, and so on.

    If an input stream is open for the current row, a call to the
    method next will implicitly close it. A ResultSet object’s warning
    chain is cleared when a new row is read.


    As a representation this means the statement is executed once and when iterated is iterated over the result of that execution.


    But how the result from database is handled depends really on the implementation. To make a contrast I will refer two databases MSSQL, MYSQL.

    MSSQL

    The documentation of MSSQL driver that comments exactly how the results are handled you can find here:

    There are two types of result sets: client-side and server-side.

    Client-side result sets are used when the results can fit in the
    client process memory. These results provide the fastest performance
    and are read by the Microsoft JDBC Driver for SQL Server in their
    entirety from the database. These result sets do not impose additional
    load on the database by incurring the overhead of creating server-side
    cursors. However, these types of result sets are not updatable.

    Server-side result sets can be used when the results do not fit in the
    client process memory or when the result set is to be updatable. With
    this type of result set, the JDBC driver creates a server-side cursor
    and fetches rows of the result set transparently as the user scrolls
    through it.

    MySQL

    MySql implementation of JDBC interface that you can read here:

    By default, ResultSets are completely retrieved and stored in memory.
    In most cases this is the most efficient way to operate, and due to
    the design of the MySQL network protocol is easier to implement. If
    you are working with ResultSets that have a large number of rows or
    large values, and cannot allocate heap space in your JVM for the
    memory required, you can tell the driver to stream the results back
    one row at a time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using a MySQL database and accessing it through Java. PreparedStatement prep1 = this.connection.prepareStatement(
When using a PreparedStatement in JDBC, should I close the PreparedStatement first or the
I'm getting the following exception when executing the first preparedstatement after a period of
Does use of PreparedStatements and ResultSets creates a new database instance everytime they are
I use this code to get a Blob from a MySql database and it
I am trying to retrieve a blob from a postgres database using the jdbc
in java.How to save a result of a sql query into a variable? java.sql.PreparedStatement
My question : I'm wondering why the results from a query from a prepared
I am trying to make a select from a table, which works fine with
Next to the addBatch() method of PreparedStatement there is also an addBatch(String) method in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.