title: Configure Tomcat 8 with Postgres
body: <p>I want to configure Tomcat 8 with PostgreSQL</p>
  
  <p>I added this in context.xml</p>
  
  <pre><code>&lt;Resource name="jdbc/DefaultDB" auth="Container" type="javax.sql.DataSource"
            username="postgres" password="qwerty"
            url="jdbc:postgresql://localhost:5432/crm"
            driverClassName="org.postgresql.Driver"
            initialSize="5" maxWait="5000"
            maxActive="120" maxIdle="5"
            validationQuery="select 1"
            poolPreparedStatements="true"/&gt;
  </code></pre>
  
  <p>And I tried to run this Java code:</p>
  
  <pre><code>public String init()
      {
          String user_name = null;
          try
          {
              Context ctx = new InitialContext();
              if (ctx == null)
                  throw new Exception("Boom - No Context");
  
              DataSource ds = (DataSource) ctx.lookup("jdbc/DefaultDB");
  
              if (ds != null)
              {
                  Connection conn = ds.getConnection();
  
                  if (conn != null)
                  {
                      Statement stmt = conn.createStatement();
                      ResultSet rst = stmt.executeQuery("select id, user_name from user where username = " + user);
                      if (rst.next())
                      {
                          user_name = rst.getString("user_name");
                      }
                      conn.close();
                  }
              }
          }
          catch (Exception e)
          {
              e.printStackTrace();
          }
  
          return user_name;
      }
  </code></pre>
  
  <p>But for some reason after I added this code Tomcat is not starting. Do you have any idea where I'm wrong?</p>
  
  <p>I get this in Tomcat log file:</p>
  
  <pre><code>    28-Mar-2016 10:37:07.955 WARNING [localhost-startStop-1] org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory.getObjectInstance Name = DefaultDB Property maxActive is not used in DBCP2, use maxTotal instead. maxTotal default value is 8. You have set value of "120" for "maxActive" property, which is being ignored.
      28-Mar-2016 10:37:07.956 WARNING [localhost-startStop-1] org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory.getObjectInstance Name = DefaultDB Property maxWait is not used in DBCP2 , use maxWaitMillis instead. maxWaitMillis default value is -1. You have set value of "5000" for "maxWait" property, which is being ignored.
  
  javax.naming.NameNotFoundException: Name [jdbc/DefaultDB] is not bound in this Context. Unable to find [jdbc].
  </code></pre>