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

别说谁变了你拦得住时间么 提交于 2019-12-03 22:36:28

问题


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 :)


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/4687514/can-i-create-support-multiple-database-transactions-on-a-single-connection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!