title: Problems importing derby drivers in glassfish
body: <p>Good day to everyone,</p>
  
  <p>I'm having some problems making Glassfish 3.1.2 seeing some imported jars. Because this i my grad project i have constraints. I cannot use anything else than Glassfish, Netbeans and i cannot use Maven, Hibernate, Ear or whathever.</p>
  
  <p>I'm working with the embedded Derby driver. (I can use another DB, but in my trials the problem remains).</p>
  
  <p>I've written some plain java code to connect to the DB:</p>
  
  <pre><code>    try{
          Connection c   = DriverManager.getConnection(URL, USER, PWD);
          Statement st   = c.createStatement();                
          st.executeUpdate("CREATE TABLE Users" +
                           " (ACCOUNT VARCHAR(20) PRIMARY KEY," +
                           " PWD VARCHAR(20) NOT NULL," +
                           " USERTYPE INTEGER NOT NULL)");
  
                         ...
  
         }
         catch (SQLException x){
           System.out.println(x);  
         }
  </code></pre>
  
  <p>It's ugly, it doesn't use connection pools, it works. I'll use them later.
  Obviously i had to add derbyclient.jar to the libs.</p>
  
  <p>The problem arises when i try to use this method inside a servlet:</p>
  
  <pre><code>protected void processRequest(HttpServletRequest req, HttpServletResponse res)
          throws ServletException, IOException {
  
      try{           
          DriverManager.registerDriver(org.apache.derby.jdbc.ClientDriver);            
          Connection c = DriverManager.getConnection(dbUsr, pwd, url);            
          Statement st = c.createStatement();            
          ResultSet rs = st.executeQuery(query);
  
                           ...
  
         }catch (SQLException e){
          ServletException e1 = new ServletException(e.getMessage());
          throw e1;
      }
  </code></pre>
  
  <p>I cannot compile the servlet because "Package org.apache.derby.jdbc does not exists".</p>
  
  <p>I can provide some more informations (20+ hours of reading and unsuccesful trials):</p>
  
  <ul>
  <li>The servlet and the java code are in the same project, so derbyclient.jar should be seen by both of them.</li>
  <li>When i write org.apache.berby netbeans shows me the package navigator for auto-completion, so somewhere it knows that there is a jar.</li>
  <li>I tried to put derbyclient.jar inside:
  <ul>
  <li>Glassfish/glassfish/domains/domain1/lib</li>
  <li>Glassfish/glassfish/domains/domain1/lib/ext</li>
  <li>Glassfish/glassfish/lib</li>
  </ul></li>
  <li>Tried without driver registration, the java code works without it, but i get "javax.servlet.ServletException: No suitable driver found for app". I find it reasonable.</li>
  </ul>
  
  <p>I am at my wits end. Does someone care to help?</p>
  
  <p>EDIT:</p>
  
  <p>Yesterday I got news from the teacher: she blames Netbeans IDE for losing track of the jars. It seems to be a known bug.</p>
  
  <p>I was warmly encouraged to switch to a tomcat server. I'll surely try it, bu i'll keep working to get this problem solved. Any other good ideas?</p>