我是新手,任何帮助将不胜感激。我在 Amazon EC2 上安装了一个 Webapp。我已经在 Amazon EC2 上安装了 Tomcat7 和 MySQL 5.5。
我在 servlet 中使用以下代码进行 JDBC-MySQL 连接
Connection connection;
Statement statement;
ResultSet rs = null;
try {
// load Connector/J
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(JDBC_MYSQL_STRING);
System.out.println(TAG + " Connection with MySQL established");
statement = connection.createStatement();
....
....
....
rs.close();
statement.close();
connection.close();
} catch (ClassNotFoundException ex) {
Log.log(Level.SEVERE, "ClassNotFoundException", ex);
} catch (SQLException e) {
for (Throwable t : e) {
System.out.println(t.getMessage());
}
我已将mysql-connector-java-5.1.13-bin.jar
Connector/J 包含在 Netabeans 的 Library 文件夹中,并war
在 Amazon ec2 的 tomcat7 上部署了文件。
我的问题
我了解到 JDBC-MySQL 连接是非常耗时的操作,connection pools
可用于保持实时连接,这将减少连接所消耗的时间。我是新手,已经阅读了我的博客,但无法理解如何设置connection pool
以及如何在 servlet 中使用它?
谢谢。