title: How to fetch data from table having millions of records using spring jdbc template
body: <p>I am trying to fetch data using spring jdbc template.
  The table has millions of records.</p>
  
  <p>Using the below code is taking infinite time and finally i have stop running the code.</p>
  
  <pre><code>private static final String CLIENTDATA_QUERY = "select logtime, clientip, clientagent, uri from client_data";
  public List&lt;ClientDataModel&gt; readFromClientDataDB() {
  //      jdbcTemplate.setFetchSize(1000);
          List&lt;ClientDataModel&gt; clientData = jdbcTemplate.query(CLIENTDATA_QUERY, new RowMapper&lt;ClientDataModel&gt;() {
  
              @Override
              public ClientDataModel mapRow(ResultSet rs, int rowNum) throws SQLException {
                  ClientDataModel model = new ClientDataModel();
                  model.setLogtime(rs.getString("logtime"));
                  model.setClientIP(rs.getString("clientip"));
                  model.setClientAgent(rs.getString("clientagent"));
  //              model.setUri(rs.getString("uri"));
                  return model;
              }
          });
  
          System.out.println("Client Data Size :" + clientData.size());
          return clientData;
      }
  </code></pre>
  
  <p>Please can someone suggest how can i retrieve records from a huge table in the most efficient way.</p>
  
  <p>All records are required to be fetched and then the code for further logic begins. This is on server side.</p>