Forums Register Login

Is it possible to use batch for SQL select statment

+Pie Number of slices to send: Send
Is it possible to use batch for SQL select statment?
I m using prepared statement-which is setting one argument and then immedietely it fires a SQL select query to fetch the data. This way it's not very effient as i keep on getting this argument in bulk and they are grouped in certain manner.
What i want to know whether i can addBatch() and then executeBatch() or some other varient of batch updates in SQL select kind of queries?
for(int i=0; i < someLenth; i++)
{
pstmt.setLong(1,arr[i])
pstmt.addBatch();
}
pstmt.executeBatch();
where pstmt is just a prepared statement.
I need a resultSet object just the way i can get it from pstmt.executeQuery()
+Pie Number of slices to send: Send
I dont think you can do in this way.

Just a suggestion
you make a single query using IN clause and then you will get one resultset and process your data in code.
HashMap/Treemap will help you to implement this logic

Shailesh
+Pie Number of slices to send: Send
Thanks Shailesh-but IN expects all the values to be resolved at compile time-i just cant iterate thru this array and then use IN.
+Pie Number of slices to send: Send
However I dont recommend to use Statement over PreparedStatement but for this case you can use Statement to avoid multiple hit to server.

I will look for, that how it can be done with preparedstatement.

Shailesh
+Pie Number of slices to send: Send
Monu,
You can still use a prepared statement:
select fields from table where id in (?, ?, ?, ?)

If you search this forum for batching, I made some posts on preparing a few different size in clauses. This gives a performance benefit as you reuse the same set of preparaed statements each time.
straws are for suckers. tiny ads are for attractive people.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 4502 times.
Similar Threads
How to Implement an Advanced Form Search w/PreparedStatements
Preapred stmt
SQL
Escaping special characters
Why does a JDBC batch update return a -2
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 11:33:00.