开发者

Does MySql support connection pooling for Java SE applications?

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/MysqlConne开发者_如何学GoctionPoolDataSource.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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜