提交 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
<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
<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:
</p>
<pre>
// init
import org.h2.jdbcx.*;
...
JdbcConnectionPool cp = JdbcConnectionPool.create(
"jdbc:h2:~/test", "sa", "sa");
// use
Connection conn = cp.getConnection();
...
conn.close();
// dispose
cp.dispose();
import java.sql.*;
import org.h2.jdbcx.JdbcConnectionPool;
public class Test {
public static void main(String[] args) throws Exception {
JdbcConnectionPool cp = JdbcConnectionPool.create(
"jdbc:h2:~/test", "sa", "sa");
for (int i = 0; i &lt; args.length; i++) {
Connection conn = cp.getConnection();
conn.createStatement().execute(args[i]);
conn.close();
}
cp.dispose();
}
}
</pre>
<br /><a name="fulltext"></a>
......
......@@ -42,17 +42,20 @@ import org.h2.message.Message;
* MiniConnectionPoolManager written by Christian d'Heureuse (Java 1.5)
* </a>. It is used as follows:
* <pre>
* // init
* import org.h2.jdbcx.*;
* ...
* JdbcConnectionPool cp = JdbcConnectionPool.create(
* "jdbc:h2:~/test", "sa", "sa");
* // use
* Connection conn = cp.getConnection();
* ...
* conn.close();
* // dispose
* cp.dispose();
* import java.sql.*;
* import org.h2.jdbcx.JdbcConnectionPool;
* public class Test {
* public static void main(String[] args) throws Exception {
* JdbcConnectionPool cp = JdbcConnectionPool.create(
* "jdbc:h2:~/test", "sa", "sa");
* for (int i = 0; i &lt; args.length; i++) {
* Connection conn = cp.getConnection();
* conn.createStatement().execute(args[i]);
* conn.close();
* }
* cp.dispose();
* }
* }
* </pre>
*
* @author Christian d'Heureuse
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论