我是新的,任何帮助将不胜感激。我在Amazon EC2上安装了一个Web应用程序。我已经在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());
}我在Netabeans的Library文件夹中包含了Connector / J的mysql-connector-java-5.1.13-bin.jar,并在Amazon ec2的tomcat7上部署了war文件。
我的问题
我已经了解到,JDBC-MySQL连接非常耗时,并且connection pools可用于保持实时连接,这将减少连接所耗费的时间。我是新手,已经阅读了我的博客,但无法理解如何设置connection pool以及如何在servlet中使用它?
谢谢。