title: Inserting data through GUI into sql server
body: <p>I'm able to execute sql statements by writing the sql codes (Insert etc) on Eclipse and it is being displayed into sql server correctly. Connection has been done. But what should I do when a user wants to add data through a GUI interface (text field) and the data need to get stored into the database automatically ??</p>
  
  <p>my code in the ADD button, but i'm getting the Error: java.lang.NullPointerException ! Help please..</p>
  
  <pre><code>try {
         String pid = ProductID.getText();
         String sql = "insert into Products_tbl values (' " +pid + " ')";
  
         // Running the sql query
         rs = st.executeQuery(sql);
  
         int count = 0;
         while (rs.next()) {
           count = count + 1;
         }
  
         if (count == 1) {
            JOptionPane.showMessageDialog(null, "Welcome");
         } 
         else if (count &gt; 1) {
           JOptionPane.showMessageDialog(null,"Duplicate User Access Denied");
         }
         else {
           JOptionPane.showMessageDialog(null, " User Not Found ");
         }
  }
  
  catch (Exception ex) {
        System.out.println("Error: " + ex); 
  }
  </code></pre>