MySql 是否支持 Java SE 应用程序的连接池?

发布于 2024-09-08 18:26:11 字数 1196 浏览 5 评论 0原文

从我读过的示例和 MysqlConnectionPoolDataSource 的文档中 http://www.control.auc.dk/~04gr733/filer/javadoc-DB-driver/com/mysql/jdbc/jdbc2/可选/MysqlConnectionPoolDataSource.html< /a> 看来 Java SE 应用程序无法使用连接池。这是真的吗?我可以让连接池适用于 MySql 吗?

对于PreparedStatement池来说也是如此吗?

更新: 我从 MySQL 网站上看到了有关连接池的以下内容。

    /*
     * Create a JNDI Initial context to be able to
     *  lookup  the DataSource
     *
     * In production-level code, this should be cached as
     * an instance or static variable, as it can
     * be quite expensive to create a JNDI context.
     *
     * Note: This code only works when you are using servlets
     * or EJBs in a J2EE application server. If you are
     * using connection pooling in standalone Java code, you
     * will have to create/configure datasources using whatever
     * mechanisms your particular connection pooling library
     * provides.
     */

这促使我寻找一种方法来为 Java SE 应用程序实现这一点。但重新阅读它,在我看来,他们正在引用您获取数据源引用的方式。我是否可以不使用依赖项注入框架或手动插入对我的 DAO 对象的数据源的依赖项?我打算尝试一下。

From the examples that I have read and from the documentation on MysqlConnectionPoolDataSource at http://www.control.auc.dk/~04gr733/filer/javadoc-DB-driver/com/mysql/jdbc/jdbc2/optional/MysqlConnectionPoolDataSource.html it seems that Java SE applications cannot use connection pooling. Is this true? Can I get connection pooling to work for MySql?

Does the same go for PreparedStatement pooling?

UPDATE:
I came across the following from the MySQL website with regards to their connection pooling.

    /*
     * Create a JNDI Initial context to be able to
     *  lookup  the DataSource
     *
     * In production-level code, this should be cached as
     * an instance or static variable, as it can
     * be quite expensive to create a JNDI context.
     *
     * Note: This code only works when you are using servlets
     * or EJBs in a J2EE application server. If you are
     * using connection pooling in standalone Java code, you
     * will have to create/configure datasources using whatever
     * mechanisms your particular connection pooling library
     * provides.
     */

This is what has made me look at a way to get this right for a Java SE application. But re-re-reading it, it seems to me that they are making reference to the manner in which you obtain a reference to the datasource. Could I not use a dependency injection framework or manual insert a dependency on the datasource for my DAO object? I am going to give that a try.

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

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

发布评论

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

评论(2

月下凄凉 2024-09-15 18:26:11

您可以使用一些第三方 JDBC 连接池,例如:
BoneCP , C3P0DBCP

You could use some third party Connection Pool for JDBC such as:
BoneCP , C3P0 or DBCP

天荒地未老 2024-09-15 18:26:11

MysqlConnectionPoolDataSource 本身不会执行此操作,请使用类似 c3p0 的内容,或者查看示例位于连接池上的SDN

The MysqlConnectionPoolDataSource won't do it itself, use something like c3p0 for that, or look at the examples at the SDN on Connection Pooling.

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