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");
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?
source
share