title: Getting Null Pointer in PreparedStatement.close()
body: <p>im trying to insert values from textfield to mySql using jdbc but my problem is im having a null pointer error when closing my prepared statement. here's my code</p>
  
  <pre><code> private Connection con;
   private Statement stm;
   private ResultSet rs;
   private PreparedStatement ps ;
  
  
  
  public void dbConnect(){
      try{
          Class.forName("com.mysql.jdbc.Driver");
          this.con = DriverManager.getConnection("jdbc:mysql://localhost:3306/dbTestDrive"
                  + "", "root", "password");
  
      }
      catch(ClassNotFoundException ex){}
      catch(SQLException ex){}
  }
  
   public boolean insert(Member member)throws SQLException{
      this.dbConnect();
      boolean success = false;
      String query = "INSERT INTO try VALUES(?, ?)";
              try {
          this.ps = this.con.prepareStatement(query);
          this.ps.setString(1, member.getMemberId());
          this.ps.setString(2, member.getFirstName());
  
  
         int rows = this.ps.executeUpdate();
          if(rows&gt;0){
              success = true;
          }
  
      } catch (SQLException ex) {
          ex.printStackTrace();
          throw ex;
      } finally{
          this.ps.close(); // this is my line: 56 (im getting null pointer here)
          this.con.close();
      }
  
      return success;
  }
  </code></pre>
  
  <p>here's the stacktrace:</p>
  
  <pre><code>   Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
  at rtu.tomis.dao.MemberDao.insert(MemberDao.java:56)
  at rtu.tomis.gui.AddMemberView.btnSaveActionPerformed(AddMemberView.java:993)
  at rtu.tomis.gui.AddMemberView.access$800(AddMemberView.java:21)
  at rtu.tomis.gui.AddMemberView$9.actionPerformed(AddMemberView.java:476)
  </code></pre>
  
  <p>thank u for your help</p>