How to set fetchSize for concrete query?How to use fetch size in JdbcTemplate to process 20+ millions rows?How do I efficiently iterate over each entry in a Java Map?Fastest way to determine if an integer's square root is an integerHow do I read / convert an InputStream into a String in Java?How do I generate random integers within a specific range in Java?How do I determine whether an array contains a particular value in Java?Why use getters and setters/accessors?How to make mock to void methods with MockitoHow do I convert a String to an int in Java?How do I fix android.os.NetworkOnMainThreadException?How to install Java 8 on Mac
Team member is vehemently against code formatting
Shell builtin `printf` line limit?
Is it safe to redirect stdout and stderr to the same file without file descriptor copies?
Surface of the 3x3x3 cube as a graph
Why do the i8080 I/O instructions take a byte-sized operand to determine the port?
How do I write real-world stories separate from my country of origin?
How to tease a romance without a cat and mouse chase?
csname in newenviroment
Why is this python script running in background consuming 100 % CPU?
What does it mean for something to be strictly less than epsilon for an arbitrary epsilon?
How could the B-29 bomber back up under its own power?
Caught with my phone during an exam
What is the winged creature on the back of the Mordenkainen's Tome of Foes book?
Existence of a model of ZFC in which the natural numbers are really the natural numbers
Negative impact of having the launch pad away from the Equator
mmap: effect of other processes writing to a file previously mapped read-only
size of pointers and architecture
How to become an Editorial board member?
What is this dime sized black bug with white on the segments near Loveland Colorodao?
Meaning of "half-crown enclosure"
"Official wife" or "Formal wife"?
Is there a solution to paying high fees when opening and closing lightning channels once we hit a fee only market?
How could Dwarves prevent sand from filling up their settlements
Nunc est bibendum: gerund or gerundive?
How to set fetchSize for concrete query?
How to use fetch size in JdbcTemplate to process 20+ millions rows?How do I efficiently iterate over each entry in a Java Map?Fastest way to determine if an integer's square root is an integerHow do I read / convert an InputStream into a String in Java?How do I generate random integers within a specific range in Java?How do I determine whether an array contains a particular value in Java?Why use getters and setters/accessors?How to make mock to void methods with MockitoHow do I convert a String to an int in Java?How do I fix android.os.NetworkOnMainThreadException?How to install Java 8 on Mac
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I want to set fetchSize only for one query and I can't find appropriate api for that.
my code looks like this:
jdbcTemplate.query(query, new RowCallbackHandler() {
@Override
public void processRow(ResultSet rs) throws SQLException ...
);
How can I pass fetchSize to the query ?
java spring jdbc spring-jdbc jdbctemplate
add a comment |
I want to set fetchSize only for one query and I can't find appropriate api for that.
my code looks like this:
jdbcTemplate.query(query, new RowCallbackHandler() {
@Override
public void processRow(ResultSet rs) throws SQLException ...
);
How can I pass fetchSize to the query ?
java spring jdbc spring-jdbc jdbctemplate
add a comment |
I want to set fetchSize only for one query and I can't find appropriate api for that.
my code looks like this:
jdbcTemplate.query(query, new RowCallbackHandler() {
@Override
public void processRow(ResultSet rs) throws SQLException ...
);
How can I pass fetchSize to the query ?
java spring jdbc spring-jdbc jdbctemplate
I want to set fetchSize only for one query and I can't find appropriate api for that.
my code looks like this:
jdbcTemplate.query(query, new RowCallbackHandler() {
@Override
public void processRow(ResultSet rs) throws SQLException ...
);
How can I pass fetchSize to the query ?
java spring jdbc spring-jdbc jdbctemplate
java spring jdbc spring-jdbc jdbctemplate
asked Mar 23 at 20:54
gstackoverflowgstackoverflow
10.5k48178382
10.5k48178382
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
This can be done using PreparedStatementSetter
(JavaDoc)
Given the query
select * from mytable where user_id > ?
You can use
jdbcTemplate.query(query,
new PreparedStatementSetter()
@Override
public void setValues(final PreparedStatement ps) throws SQLException
ps.setInt(1, userId);
ps.setFetchSize(500);
,
new RowCallbackHandler()
@Override
public void processRow(final ResultSet rs) throws SQLException
...
);
Or in a more compact form
jdbcTemplate.query(
query,
ps ->
ps.setInt(1, userId);
ps.setFetchSize(500);
,
rs -> ...
);
Keep in mind that
Implementations are responsible for setting any necessary parameters.
SQL with placeholders will already have been supplied.
For a single resulting object, use the
public <T> T query(String sql,
PreparedStatementSetter pss,
ResultSetExtractor<T> rse) throws DataAccessException;
method. For example
jdbcTemplate.query(
query,
new ArgumentPreparedStatementSetter(new Object[] balanceId),
rs ->
final String field1 = rs.getString("field1");
// Get other fields and construct the resulting object
return new YourClass(field1, ...);
);
1
It looks perfect!
– gstackoverflow
Mar 23 at 21:08
1
@gstackoverflow The thing is I've never seen a tutorial which uses it. That's why it is so "hidden" inside the documentation.
– LppEdd
Mar 23 at 21:09
@gstackoverflow btw, remember you need to set values manually.
– LppEdd
Mar 23 at 21:14
what do you mean?
– gstackoverflow
Mar 23 at 21:15
1
Your advice ps.setInt(1, userId) is helpful for me. Thank you for your efforts
– gstackoverflow
Mar 23 at 21:47
|
show 14 more comments
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55318272%2fhow-to-set-fetchsize-for-concrete-query%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
This can be done using PreparedStatementSetter
(JavaDoc)
Given the query
select * from mytable where user_id > ?
You can use
jdbcTemplate.query(query,
new PreparedStatementSetter()
@Override
public void setValues(final PreparedStatement ps) throws SQLException
ps.setInt(1, userId);
ps.setFetchSize(500);
,
new RowCallbackHandler()
@Override
public void processRow(final ResultSet rs) throws SQLException
...
);
Or in a more compact form
jdbcTemplate.query(
query,
ps ->
ps.setInt(1, userId);
ps.setFetchSize(500);
,
rs -> ...
);
Keep in mind that
Implementations are responsible for setting any necessary parameters.
SQL with placeholders will already have been supplied.
For a single resulting object, use the
public <T> T query(String sql,
PreparedStatementSetter pss,
ResultSetExtractor<T> rse) throws DataAccessException;
method. For example
jdbcTemplate.query(
query,
new ArgumentPreparedStatementSetter(new Object[] balanceId),
rs ->
final String field1 = rs.getString("field1");
// Get other fields and construct the resulting object
return new YourClass(field1, ...);
);
1
It looks perfect!
– gstackoverflow
Mar 23 at 21:08
1
@gstackoverflow The thing is I've never seen a tutorial which uses it. That's why it is so "hidden" inside the documentation.
– LppEdd
Mar 23 at 21:09
@gstackoverflow btw, remember you need to set values manually.
– LppEdd
Mar 23 at 21:14
what do you mean?
– gstackoverflow
Mar 23 at 21:15
1
Your advice ps.setInt(1, userId) is helpful for me. Thank you for your efforts
– gstackoverflow
Mar 23 at 21:47
|
show 14 more comments
This can be done using PreparedStatementSetter
(JavaDoc)
Given the query
select * from mytable where user_id > ?
You can use
jdbcTemplate.query(query,
new PreparedStatementSetter()
@Override
public void setValues(final PreparedStatement ps) throws SQLException
ps.setInt(1, userId);
ps.setFetchSize(500);
,
new RowCallbackHandler()
@Override
public void processRow(final ResultSet rs) throws SQLException
...
);
Or in a more compact form
jdbcTemplate.query(
query,
ps ->
ps.setInt(1, userId);
ps.setFetchSize(500);
,
rs -> ...
);
Keep in mind that
Implementations are responsible for setting any necessary parameters.
SQL with placeholders will already have been supplied.
For a single resulting object, use the
public <T> T query(String sql,
PreparedStatementSetter pss,
ResultSetExtractor<T> rse) throws DataAccessException;
method. For example
jdbcTemplate.query(
query,
new ArgumentPreparedStatementSetter(new Object[] balanceId),
rs ->
final String field1 = rs.getString("field1");
// Get other fields and construct the resulting object
return new YourClass(field1, ...);
);
1
It looks perfect!
– gstackoverflow
Mar 23 at 21:08
1
@gstackoverflow The thing is I've never seen a tutorial which uses it. That's why it is so "hidden" inside the documentation.
– LppEdd
Mar 23 at 21:09
@gstackoverflow btw, remember you need to set values manually.
– LppEdd
Mar 23 at 21:14
what do you mean?
– gstackoverflow
Mar 23 at 21:15
1
Your advice ps.setInt(1, userId) is helpful for me. Thank you for your efforts
– gstackoverflow
Mar 23 at 21:47
|
show 14 more comments
This can be done using PreparedStatementSetter
(JavaDoc)
Given the query
select * from mytable where user_id > ?
You can use
jdbcTemplate.query(query,
new PreparedStatementSetter()
@Override
public void setValues(final PreparedStatement ps) throws SQLException
ps.setInt(1, userId);
ps.setFetchSize(500);
,
new RowCallbackHandler()
@Override
public void processRow(final ResultSet rs) throws SQLException
...
);
Or in a more compact form
jdbcTemplate.query(
query,
ps ->
ps.setInt(1, userId);
ps.setFetchSize(500);
,
rs -> ...
);
Keep in mind that
Implementations are responsible for setting any necessary parameters.
SQL with placeholders will already have been supplied.
For a single resulting object, use the
public <T> T query(String sql,
PreparedStatementSetter pss,
ResultSetExtractor<T> rse) throws DataAccessException;
method. For example
jdbcTemplate.query(
query,
new ArgumentPreparedStatementSetter(new Object[] balanceId),
rs ->
final String field1 = rs.getString("field1");
// Get other fields and construct the resulting object
return new YourClass(field1, ...);
);
This can be done using PreparedStatementSetter
(JavaDoc)
Given the query
select * from mytable where user_id > ?
You can use
jdbcTemplate.query(query,
new PreparedStatementSetter()
@Override
public void setValues(final PreparedStatement ps) throws SQLException
ps.setInt(1, userId);
ps.setFetchSize(500);
,
new RowCallbackHandler()
@Override
public void processRow(final ResultSet rs) throws SQLException
...
);
Or in a more compact form
jdbcTemplate.query(
query,
ps ->
ps.setInt(1, userId);
ps.setFetchSize(500);
,
rs -> ...
);
Keep in mind that
Implementations are responsible for setting any necessary parameters.
SQL with placeholders will already have been supplied.
For a single resulting object, use the
public <T> T query(String sql,
PreparedStatementSetter pss,
ResultSetExtractor<T> rse) throws DataAccessException;
method. For example
jdbcTemplate.query(
query,
new ArgumentPreparedStatementSetter(new Object[] balanceId),
rs ->
final String field1 = rs.getString("field1");
// Get other fields and construct the resulting object
return new YourClass(field1, ...);
);
edited Mar 23 at 21:50
answered Mar 23 at 20:59
LppEddLppEdd
10.2k31849
10.2k31849
1
It looks perfect!
– gstackoverflow
Mar 23 at 21:08
1
@gstackoverflow The thing is I've never seen a tutorial which uses it. That's why it is so "hidden" inside the documentation.
– LppEdd
Mar 23 at 21:09
@gstackoverflow btw, remember you need to set values manually.
– LppEdd
Mar 23 at 21:14
what do you mean?
– gstackoverflow
Mar 23 at 21:15
1
Your advice ps.setInt(1, userId) is helpful for me. Thank you for your efforts
– gstackoverflow
Mar 23 at 21:47
|
show 14 more comments
1
It looks perfect!
– gstackoverflow
Mar 23 at 21:08
1
@gstackoverflow The thing is I've never seen a tutorial which uses it. That's why it is so "hidden" inside the documentation.
– LppEdd
Mar 23 at 21:09
@gstackoverflow btw, remember you need to set values manually.
– LppEdd
Mar 23 at 21:14
what do you mean?
– gstackoverflow
Mar 23 at 21:15
1
Your advice ps.setInt(1, userId) is helpful for me. Thank you for your efforts
– gstackoverflow
Mar 23 at 21:47
1
1
It looks perfect!
– gstackoverflow
Mar 23 at 21:08
It looks perfect!
– gstackoverflow
Mar 23 at 21:08
1
1
@gstackoverflow The thing is I've never seen a tutorial which uses it. That's why it is so "hidden" inside the documentation.
– LppEdd
Mar 23 at 21:09
@gstackoverflow The thing is I've never seen a tutorial which uses it. That's why it is so "hidden" inside the documentation.
– LppEdd
Mar 23 at 21:09
@gstackoverflow btw, remember you need to set values manually.
– LppEdd
Mar 23 at 21:14
@gstackoverflow btw, remember you need to set values manually.
– LppEdd
Mar 23 at 21:14
what do you mean?
– gstackoverflow
Mar 23 at 21:15
what do you mean?
– gstackoverflow
Mar 23 at 21:15
1
1
Your advice ps.setInt(1, userId) is helpful for me. Thank you for your efforts
– gstackoverflow
Mar 23 at 21:47
Your advice ps.setInt(1, userId) is helpful for me. Thank you for your efforts
– gstackoverflow
Mar 23 at 21:47
|
show 14 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55318272%2fhow-to-set-fetchsize-for-concrete-query%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown