Jetty mysql database pooling

I'm trying to do something like simple: configure a small pool of database connections so that the servlet (only one) does not create my server with 1 connection per second.

In Ubuntu 10.04, with the latest update / update, I use Eclipse Jetty 8.1.5.v20120716. I am trying to connect to a server MySQL 5.1.

My servlet is called gcm, so ${jetty}/contextsI have this file in 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>

When I start Jetty with java -jar start.jar -port=8080, everything starts fine until I try to hit the database from my servlet. Part of the processing of the request code is as follows:

 public static List<String> getDevices()
    throws javax.naming.NamingException, java.sql.SQLException {
    synchronized (regIds) {
        InitialContext ctx = new InitialContext();
        DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/myds");
        Connection conn = null;
        Statement stmt = null;

        try {
            conn = ds.getConnection();

            stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery("select * from chatdevice");

        //blah,blah,blah...

The error I get is:

    javax.naming.NameNotFoundException; remaining name 'jdbc/myds'
        at org.eclipse.jetty.jndi.NamingContext.lookup(NamingContext.java:500)
        at org.eclipse.jetty.jndi.NamingContext.lookup(NamingContext.java:531)
        at org.eclipse.jetty.jndi.NamingContext.lookup(NamingContext.java:531)
        at org.eclipse.jetty.jndi.NamingContext.lookup(NamingContext.java:546)
        at org.eclipse.jetty.jndi.java.javaRootURLContext.lookup(javaRootURLContext.java:112)
        at javax.naming.InitialContext.lookup(InitialContext.java:409) 
        at com.google.android.gcm.demo.server.Datastore.getDevices(Datastore.java:98)

How to get Jetty to search for database code?

+5
source share
2

(https://dev.eclipse.org/mailman/listinfo/jetty-users), .

(, !) :

, , , , . - .

- , : http://wiki.eclipse.org/Jetty/Feature/JNDI - , , .

, javaee-style, web.xml. - , , .

( ), jndi WEB-INF/jetty-env.xml, xml . , , web.xml   java: comp/env, java: comp/env ( , xml , jetty-env.xml):

, WEB-INF/jetty-env.xml:

 <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>
  <Call name="bindToENC">
     <Arg>jdbc/myds</Arg>
  </Call>   
 </New>

bindToENC , java: comp/env. , java: comp/env/my/foo bindToENC "my/foo".

- www.webtide.com - , Jetty CometD. _______________________________________________ Jetty-users@eclipse.org https://dev.eclipse.org/mailman/listinfo/jetty-users

( ). WEB-INF WEB-INF ... , jetty-env.xml WEB -INF.

:

, , , , , , , jetty-env.xml.

wiki jetty-env.xml : http://wiki.eclipse.org/Jetty/Reference/jetty-env.xml

, , .

// . connection refused from 127.0.0.1 /var/log/auth.log.

, denyhosts, , , - ALL: 127.0.0.1... , .

, , , MySQL .

+5

web.xml

<resource-ref>
    <res-ref-name>jdbc/myds</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>
0

All Articles