title: Having Null Pointer Exception and JDBC.sql exception User not Found
body: <p>I'm making my user log in and logged out whenever I get my user signed up it provides an error. </p>
  
  <p>List of Problems are</p>
  
  <p><strong>INFO  [stdout] (default task-6) org.h2.jdbc.JdbcSQLException: Table "USER" not found;</strong></p>
  
  <p><strong>SQL statement:
  stdout] (default task-6) INSERT INTO user(firstname, password, lastname, email) VALUES(?,?,?,?) [42102-173]</strong></p>
  
  <p><strong>ERROR [stderr] (default task-6) java.lang.NullPointerException</strong></p>
  
  <p><strong>ERROR [stderr] (default task-6)   at com.ark.beans.User.add(User.java:113)</strong></p>
  
  <p><strong>ERROR [stderr] (default task-6)   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)</strong></p>
  
  <p><strong>ERROR [stderr] (default task-6)   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)</strong></p>
  
  <p>I have checked every name and connection but isn't working for me</p>
  
  <p>This is my User class</p>
  
  <pre><code>public User() {
      try {
          Context ctx = new InitialContext();
          ds = (DataSource) ctx.lookup("java:comp/env/jdbc/database");
      } catch (NamingException e) {
          e.printStackTrace();
      }
  }
  
  public String add() {
      int i = 0;
      if (firstName != null) {
          PreparedStatement ps = null;
          Connection con = null;
          try {
              if (ds != null) {
                  con = ds.getConnection();
                  if (con != null) {
                      String sql = "INSERT INTO user(firstname, password, lastname, email) VALUES(?,?,?,?)";
                      ps = con.prepareStatement(sql);
                      ps.setString(1, firstName);
                      ps.setString(2, password);
                      ps.setString(3, lastName);
                      ps.setString(4, email);
                      i = ps.executeUpdate();
                      System.out.println("Data Added Successfully");
                  }
              }
          } catch (Exception e) {
              System.out.println(e);
          } finally {
              try {
                  con.close();
                  ps.close();
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      }
      if (i &gt; 0) {
          return "success";
      } else
          return "unsuccess";
  }
  
  public void dbData(String uName) {
      if (uName != null) {
          PreparedStatement ps = null;
          Connection con = null;
          ResultSet rs = null;
  
          if (ds != null) {
              try {
                  con = ds.getConnection();
                  if (con != null) {
                      String sql = "select firstname,password from user where firstname = '"
                              + uName + "'";
                      ps = con.prepareStatement(sql);
                      rs = ps.executeQuery();
                      rs.next();
                      dbName = rs.getString("firstname");
                      dbPassword = rs.getString("password");
                  }
              } catch (SQLException sqle) {
                  sqle.printStackTrace();
              }
          }
      }
  }
  
  public String login() {
      dbData(firstName);
      if (firstName.equals(dbName) &amp;&amp; password.equals(dbPassword)) {
          return "output";
      } else
          return "invalid";
  }
  
  public void logout() {
      FacesContext.getCurrentInstance().getExternalContext();
      FacesContext.getCurrentInstance()
              .getApplication().getNavigationHandler()
              .handleNavigation(FacesContext.getCurrentInstance(), null, "/login.xhtml");
  }
  }
  </code></pre>
  
  <p>This is context.xml</p>
  
  <pre><code>&lt;Resource name="jdbc/database" auth="Container" type="javax.sql.DataSource"
            username="root" password="password" driverClassName="com.mysql.jdbc.Driver"
            url="jdbc:mysql://localhost:3306/appdb" /&gt;
  </code></pre>
  
  <p>Form to get User Signed In</p>
  
  <pre><code>&lt;h:form id="registerForm"&gt;
      &lt;table&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;h:outputText value="Enter Your First Name:" /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;h:inputText id="fname" value="#{user.firstName}"
                               required="true" requiredMessage="Please enter your first name" /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;h:message for="fname" style="color:red" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;h:outputText value="Enter Your Last Name:" /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;h:inputText id="lname" value="#{user.lastName}"
                               required="true" requiredMessage="Please enter your last name" /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;h:message for="lname" style="color:red" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;h:outputText value="Enter Your email ID:" /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;h:inputText id="email" value="#{user.email}"
                               required="true" requiredMessage="Please enter your email id" /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;h:message for="email" style="color:red" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;h:outputText value="Enter Password :" /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;h:inputSecret id="psw" value="#{user.password}"
                                 required="true" requiredMessage="Please enter your password" /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;h:message for="psw" style="color:red" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td /&gt;
              &lt;td&gt;&lt;h:commandButton value="Register" action="#{user.add}" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;h:outputLink value="home.xhtml"&gt;Home&lt;/h:outputLink&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  &lt;/h:form&gt;
  </code></pre>