2

I'm trying to run multiple SQL queries in a single SQL server thread through a java code. I tried using batch run for my queries, but seeing the logs, my queries were running in different threads.

Is there a way to run all my queries under a single thread?

I have enabled concurrency flag for my queries so that read/write operations do not conflict and resulting in an exception.

2
  • Do you mean "one transaction"? What do you see in the logs? What do you mean by "I have enabled concurrency flag"? Commented May 4, 2012 at 6:04
  • If you want to run them in a single thread I doubt there will be any concurrency issues, however user714965 is right there's not enough information available to understand the problem properly. BTW user714965 change your name will you its weird to see the default user tag in someone with your score! Commented May 4, 2012 at 6:18

3 Answers 3

2

You have to handle the transaction manually by turning off auto commit and make a commit after you run your statements:

connection.setAutoCommit(false);
statement.executeUpdate();
connection.commit();
Sign up to request clarification or add additional context in comments.

6 Comments

Will this guarantee that I have a single thread for queries execution?
Your queries will run in one transaction in order to avoid concurrent modifications. See Using Transactions for reference.
But the point is, I'm not using my queries for transaction related purposes. I'm just creating a group of select statements to execute after a certain limit so that sql overheads are kept to minimum.
Ok, I don't get this. A batch can't be used to execute SELECT-statements.
But I have successfully used batch to exectue SELECT statements. Can you tell me why we cannot use batch for SELECT statements?
|
1

You can create pl/sql function and can put all your query into that function.

or execute multiple statement with single connection whit out closing it.

1 Comment

@Quoi I think when executing in batch, there is a single MySQL server connection and what i hoped was that the queries would run under one mysql thread. But this is not happening. I was wondering if anyone would have leads on this one.
0

I am not sure but you can create procedure for multiple sql queries and then call it from your java code. This and this may lead to the way.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.