QSqlDatabase 应该使用单连接还是多连接

发布于 2024-09-19 08:32:29 字数 119 浏览 1 评论 0原文

我有依赖类和独立类,我需要在这些类中创建数据库连接。据我了解,如果我以默认方式创建连接,所有其中使用相同的连接。

我应该为不同的类创建不同的数据库连接,还是应该使用相同的数据库连接。有什么优点和缺点? 谢谢。

I have dependent and independent classes, I need to create database connections in these classes. As I understand from Qt documentation, if I create connections in default way, all of them use same connection.

Should I create different database connections for different classes, or should I use same database connection. What are pros and cons?
Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

胡大本事 2024-09-26 08:32:29

我不确定为什么 @Dummy00001 将他的回复记录为评论而不是答案,但我同意他的观点。如果您不打算以并行方式使用数据库,则不需要多个连接,事实上,它们会浪费客户端库和服务器上的资源。

I'm not sure why @Dummy00001 logged his response as a comment rather than an answer, but I concur with him. If you aren't going to be working with the database in a parallel fashion, you don't need multiple connections, and they will, in fact, be wasteful of resources both in your client library and on the server.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文