Reputation: 131
I am executing two select queries. The result of first select query is used to get the result of second select query. Example query 1 = "Select name, accountNumber from table 1" query 2 = "Select budget_column1, budget_column2 from table2 where column3 = accountNumber which we got from select query1;
I'm trying to optimize my code . It is taking very long time to display results. How to implement prepared Statement addbatch in this kind o scenario. I have been searching but most of the examples show for insert, update , delete statement not on select statement
Upvotes: 0
Views: 1875
Reputation: 6306
The batch execution is only for modify statements (insert, update, delete), not for select.
Generally your best option is to allow the database to do joins for you and execute as few statements as possible. If you truly do need to execute 2 different queries, you will need to make sure you have indexed access to provide good performance.
Upvotes: 1
Reputation: 1491
Try combining the queries into a single query (join) and let the RDBMS optimize if needed:
select t1.name, t2.budget_column1, t2.budget_column2
from table1 as t1, table2 as t2
where t1.accountNumber = t2.column3;
Upvotes: 1