jcbown
jcbown

Reputation: 21

Can I create support multiple database transactions on a single connection?

I have created a HyperSQL Database. I was just wondering whether I could run multiple transactions on a single connection. I didn't want to spawn a new connection for each transaction due to the overhead associated with this.

Looking at some similar questions the suggestion appeared to be to create a pool of database connections and then block waiting for one to become available. This is a workable, but not desirable solution.

Background Info (if this is relevant to the answer). My application will create a new thread when some request comes in. This request will require a database transaction. Then some not insignificant time later this transaction will be committed.

Any advice appreciated :)

Upvotes: 1

Views: 2622

Answers (2)

Nuri YILMAZ
Nuri YILMAZ

Reputation: 4321

Absolutely no. every "transaction" must have begin, complete or rollback. Of course you can separate a single transaction to some parts on a single line of original transaction. no more no less.

Upvotes: 1

zellio
zellio

Reputation: 32484

You should be able to run multiple transactions over a single connection they will just have to be run one at a time so you'll have to queue or stack them and block as the transaction happens. You generally will not be able to run queries in parallel over a single connection.

Upvotes: 2

Related Questions