提交 33acc2da authored 作者: Thomas Mueller's avatar Thomas Mueller

Improved connection pool documentation

上级 b6ea5cc6
...@@ -721,23 +721,24 @@ A simple connection pool is included in H2. It is based on the ...@@ -721,23 +721,24 @@ A simple connection pool is included in H2. It is based on the
<a href="http://www.source-code.biz/snippets/java/8.htm">Mini Connection Pool Manager</a> <a href="http://www.source-code.biz/snippets/java/8.htm">Mini Connection Pool Manager</a>
from Christian d'Heureuse. There are other, more complex connection pools available, for example from Christian d'Heureuse. There are other, more complex connection pools available, for example
<a href="http://jakarta.apache.org/commons/dbcp/">DBCP</a>. <a href="http://jakarta.apache.org/commons/dbcp/">DBCP</a>.
For H2, it is about 50 times faster to get a connection from the built-in connection pool than to get For H2, it is about twice as faster to get a connection from the built-in connection pool than to get
one using DriverManager.getConnection(). The build-in connection pool is used as follows: one using DriverManager.getConnection(). The build-in connection pool is used as follows:
</p> </p>
<pre> <pre>
// init import java.sql.*;
import org.h2.jdbcx.*; import org.h2.jdbcx.JdbcConnectionPool;
... public class Test {
JdbcConnectionPool cp = JdbcConnectionPool.create( public static void main(String[] args) throws Exception {
JdbcConnectionPool cp = JdbcConnectionPool.create(
"jdbc:h2:~/test", "sa", "sa"); "jdbc:h2:~/test", "sa", "sa");
for (int i = 0; i &lt; args.length; i++) {
// use Connection conn = cp.getConnection();
Connection conn = cp.getConnection(); conn.createStatement().execute(args[i]);
... conn.close();
conn.close(); }
cp.dispose();
// dispose }
cp.dispose(); }
</pre> </pre>
<br /><a name="fulltext"></a> <br /><a name="fulltext"></a>
......
...@@ -42,17 +42,20 @@ import org.h2.message.Message; ...@@ -42,17 +42,20 @@ import org.h2.message.Message;
* MiniConnectionPoolManager written by Christian d'Heureuse (Java 1.5) * MiniConnectionPoolManager written by Christian d'Heureuse (Java 1.5)
* </a>. It is used as follows: * </a>. It is used as follows:
* <pre> * <pre>
* // init * import java.sql.*;
* import org.h2.jdbcx.*; * import org.h2.jdbcx.JdbcConnectionPool;
* ... * public class Test {
* public static void main(String[] args) throws Exception {
* JdbcConnectionPool cp = JdbcConnectionPool.create( * JdbcConnectionPool cp = JdbcConnectionPool.create(
* "jdbc:h2:~/test", "sa", "sa"); * "jdbc:h2:~/test", "sa", "sa");
* // use * for (int i = 0; i &lt; args.length; i++) {
* Connection conn = cp.getConnection(); * Connection conn = cp.getConnection();
* ... * conn.createStatement().execute(args[i]);
* conn.close(); * conn.close();
* // dispose * }
* cp.dispose(); * cp.dispose();
* }
* }
* </pre> * </pre>
* *
* @author Christian d'Heureuse * @author Christian d'Heureuse
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论