小编Ken*_*rey的帖子

jetty mysql数据库连接池

我正在尝试做一些看似简单的事情:设置一个小的数据库连接池,这样一个servlet(只有一个)不会以每秒1个连接创建我的服务器.

Ubuntu 10.04,使用最新的升级/更新,我正在使用Eclipse Jetty 8.1.5.v20120716.我正在尝试连接到MySQL 5.1服务器.

我的servlet被调用gcm,所以${jetty}/contexts,我有这个gcm.xml文件:

<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure id="wac" class="org.eclipse.jetty.webapp.WebAppContext">
  <New id="jdbc/myds" class="org.eclipse.jetty.plus.jndi.Resource">
    <Arg></Arg>
    <Arg>jdbc/myds</Arg>
    <Arg>
      <New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
        <Set name="Url">jdbc:mysql://localhost:3306/chat</Set>
        <Set name="User">root</Set>
        <Set name="Password">sillyness</Set>
      </New>
    </Arg>
  </New>
  <Set name="contextPath">/</Set>
  <Set name="war"><SystemProperty name="jetty.home" default="."/>/webapps/gcm</Set>
  <Set name="extractWAR">true</Set>
</Configure>
Run Code Online (Sandbox Code Playgroud)

当我启动Jetty时java -jar start.jar -port=8080,一切都会正常,直到我尝试从我的servlet中访问数据库.请求的代码处理部分如下所示:

 public static List<String> getDevices()
    throws javax.naming.NamingException, java.sql.SQLException {
    synchronized (regIds) {
        InitialContext ctx = new InitialContext();
        DataSource ds …
Run Code Online (Sandbox Code Playgroud)

java mysql database servlets jetty

5
推荐指数
2
解决办法
9732
查看次数

标签 统计

database ×1

java ×1

jetty ×1

mysql ×1

servlets ×1