title: Error When Using A Data Source Without A Password In Jetty 9
body: <p>I was able to make the following example project work on my system using HSQLDB and Jetty:</p>
  
  <ul>
  <li><a href="http://www.programmingforfuture.com/2011/02/in-process-mode-of-hsqldb-in-web.html" rel="nofollow">http://www.programmingforfuture.com/2011/02/in-process-mode-of-hsqldb-in-web.html</a></li>
  </ul>
  
  <p>I then wanted to convert the project to use JNDI to reference the data source.
  First, I added the following resource-ref to my <code>web.xml</code>:</p>
  
  <pre><code>&lt;resource-ref&gt;
      &lt;res-ref-name&gt;jdbc/mydatasource&lt;/res-ref-name&gt;
      &lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt;
      &lt;res-auth&gt;Container&lt;/res-auth&gt;
  &lt;/resource-ref&gt;
  </code></pre>
  
  <p>I then added the following data source to my <code>$JETTY_HOME/etc/jetty.xml</code> file:</p>
  
  <pre><code>&lt;New id="mydatasource" class="org.eclipse.jetty.plus.jndi.Resource"&gt;
      &lt;Arg&gt;&lt;/Arg&gt;
      &lt;Arg&gt;jdbc/mydatasource&lt;/Arg&gt;
      &lt;Arg&gt;
          &lt;New class="org.hsqldb.jdbc.JDBCDataSource"&gt;
              &lt;Set name="Url"&gt;file:mytestdb&lt;/Set&gt;
              &lt;Set name="User"&gt;SA&lt;/Set&gt;
              &lt;Set name="Password"&gt;&lt;/Set&gt;
          &lt;/New&gt;
      &lt;/Arg&gt;
  &lt;/New&gt;
  </code></pre>
  
  <p>...and then I referenced the data source using the following code:</p>
  
  <pre><code>try {
      //con=DriverManager.getConnection("jdbc:hsqldb:mydatabase","SA","");
  
      InitialContext context = new InitialContext();
      DataSource dataSource = (DataSource)context.lookup("java:comp/env/jdbc/mydatasource");
      con = dataSource.getConnection();
  
      con.createStatement().executeUpdate("create table contacts (name varchar(45),email varchar(45),phone varchar(45))");
  } catch (NamingException ne) {
      ne.printStackTrace(System.out);
  } catch (SQLException e) {
      e.printStackTrace(System.out);
  }
  </code></pre>
  
  <p>I then deployed the app as an exploded directory and tried to start the Jetty process. 
  When I did, it crashed and I got the following error message:</p>
  
  <pre><code># tom at toshi in ~/Downloads/jetty-distribution-9.0.4.v20130625 [19:41:34]
  $ java -jar ./start.jar                                                                                    &lt;&lt;&lt;
  2013-07-07 19:41:39.335:WARN:oejx.XmlConfiguration:main: Config error at &lt;Set name="Password"/&gt; java.lang.refle
  ct.InvocationTargetException in file:/home/tom/Downloads/jetty-distribution-9.0.4.v20130625/etc/jetty.xml
  2013-07-07 19:41:39.349:WARN:oejx.XmlConfiguration:main: Config error at &lt;New id="mydatasource" class="org.ecli
  pse.jetty.plus.jndi.Resource"&gt;&lt;Arg/&gt;&lt;Arg&gt;jdbc/mydatasource&lt;/Arg&gt;&lt;Arg&gt;|            &lt;New class="org.hsqldb.jdbc.J
  DBCDataSource"&gt;&lt;Set name="Url"&gt;file:mytestdb&lt;/Set&gt;&lt;Set name="User"&gt;SA&lt;/Set&gt;&lt;Set name="Password"/&gt;&lt;/New&gt;|       
   &lt;/Arg&gt;&lt;/New&gt; java.lang.reflect.InvocationTargetException in file:/home/tom/Downloads/jetty-distribution-9.0.4.
  v20130625/etc/jetty.xml
  java.lang.reflect.InvocationTargetException
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:601)
          at org.eclipse.jetty.start.Main.invokeMain(Main.java:509)
          at org.eclipse.jetty.start.Main.start(Main.java:651)
          at org.eclipse.jetty.start.Main.main(Main.java:99)
          ...
  </code></pre>
  
  <p>Ok, it doesn't like the fact that the password field is empty. So then I tried making this
  change in my <code>jetty.xml</code>:</p>
  
  <pre><code>    &lt;!--&lt;Set name="Password"&gt;&lt;/Set&gt;--&gt; &lt;!-- Got rid of this --&gt;
      &lt;Set name="Password" /&gt;
  </code></pre>
  
  <p>I still got the same error. So I then deleted the "Password" property from my data source
  and I was able to start Jetty! The bad news is that now I get this error when I try to do
  anything that references the database:</p>
  
  <pre><code>2013-07-07 19:49:09.682:WARN:jndi:qtp14895676-19: 
  java.lang.Exception: org.hsqldb.jdbc.JDBCDataSource: invalid RefAddr: password
          at org.hsqldb.jdbc.JDBCDataSourceFactory.getObjectInstance(Unknown Source)
          at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321)
          at org.eclipse.jetty.jndi.NamingContext.lookup(NamingContext.java:476)
          at org.eclipse.jetty.jndi.local.localContextRoot.lookup(localContextRoot.java:518)
          at org.eclipse.jetty.jndi.local.localContextRoot.lookup(localContextRoot.java:533)
          at javax.naming.InitialContext.lookup(InitialContext.java:411)
          at org.eclipse.jetty.jndi.NamingContext.lookup(NamingContext.java:468)
          at org.eclipse.jetty.jndi.NamingContext.lookup(NamingContext.java:536)
          at org.eclipse.jetty.jndi.NamingContext.lookup(NamingContext.java:536)
          at org.eclipse.jetty.jndi.NamingContext.lookup(NamingContext.java:536)
          at org.eclipse.jetty.jndi.NamingContext.lookup(NamingContext.java:551)
          at org.eclipse.jetty.jndi.java.javaRootURLContext.lookup(javaRootURLContext.java:117)
          at javax.naming.InitialContext.lookup(InitialContext.java:411)
          at Register.init(Register.java:31)
          ...
  </code></pre>
  
  <p>That warning then was followed by a null pointer exception.</p>
  
  <p>So now it appears that the HSQLDB driver is counting on the existence of the password
  field in the data source.</p>
  
  <p>So that's my catch-22: I'm not able to start Jetty with an empty password field in my
  data source, but if I omit it, the driver doesn't work.</p>
  
  <p>Does anyone know of a way to create a data source with an empty password in Jetty? </p>
  
  <p>Finally, I'm aware that I could a) not use JNDI or b) give the SA user a password. However, 
  my particular project requires that I use JNDI and not give the SA user a password.</p>