title: getting NullPointerException while executing an SQL Query JDBC
body: <p>So, Im fairly new to Java and SQL. I had an assignment to add values from a JTextfield into an SQL Database, So everything is working but I get this error  at the insert statement.:</p>
  <pre><code>Exception in thread &quot;AWT-EventQueue-0&quot; java.lang.NullPointerException: Cannot invoke &quot;org.ibex.nestedvm.Runtime.xmalloc(int)&quot; because &quot;this.rt&quot; is null
  </code></pre>
  <p>This is my Code:</p>
  <pre><code>public class sqlDataBase {
      private static final String CREATE_TABLE_EMP=&quot;CREATE TABLE Employees (&quot;
                      + &quot;ID INT NOT NULL,&quot;
                      + &quot;Name VARCHAR(45) NOT NULL,&quot;
                      + &quot;Job VARCHAR(45) NOT NULL,&quot;
                      + &quot;Salary INT NOT NULL)&quot;;
      Connection conn = null;
      Statement stmt = null;
      public void connectDB()
      {
     
          try{
            
  
              Class.forName(&quot;org.sqlite.JDBC&quot;);
              conn =DriverManager.getConnection(&quot;jdbc:sqlite:D:\\OneDrive - Higher Education Commission\\NetBeansProjects\\SalesManagementSystem\\empnet.sqlite&quot;);
              stmt = (Statement) conn.createStatement();
              JOptionPane.showMessageDialog(null, &quot;Connection to database is successful&quot;);
              stmt.execute(CREATE_TABLE_EMP);
              System.out.println(&quot;Table created&quot;);
             
              
          }catch (Exception e){
              JOptionPane.showMessageDialog(null, e);
          }
          
          try { 
              conn.close();
          } catch (SQLException ex) {
              Logger.getLogger(sqlDataBase.class.getName()).log(Level.SEVERE, null, ex);
          }
      }
      public void addEmployee(String name, String job, int id, int salary) throws SQLException
      {
          connectDB();
          String sql = &quot;INSERT INTO Employees&quot; + &quot;VALUES ('&quot;+id+&quot;', '&quot;+name+&quot;', '&quot;+job+&quot;', '&quot;+salary+&quot;')&quot;; //error in this line
          stmt.executeUpdate(sql);
      }
      
  }
  </code></pre>
  <p>This is my AddButton:</p>
  <pre><code>private void AddEmployeeButtonActionPerformed(java.awt.event.ActionEvent evt) { 
  String name, job;
          int salary, id;
          name = (AddEmployeeName_TextField.getText());
          job = (AddEmployeeJob_TextField.getText());
          salary=Integer.parseInt(AddEmployeeSalary_TextField.getText());
          id=Integer.parseInt(AddEmployeeID_TextField.getText());
   sqlDataBase update = new sqlDataBase();
          try {
              update.addEmployee(name,job,id,salary); //this button is in different class
          } catch (SQLException ex) {
              Logger.getLogger(AddEmployee.class.getName()).log(Level.SEVERE, null, ex);
          }
      }                  
  </code></pre>
  <p>These are my imports for sql:</p>
  <pre><code>import java.util.logging.Level;
  import java.util.logging.Logger;
  import javax.swing.JOptionPane;
  import java.sql.DriverManager;
  import java.sql.Connection;
  import java.sql.SQLException;
  import java.sql.Statement;
  </code></pre>
  <p>The table creates successfully and the database connects too
  I have been trying for quite a while to figure out what's going on but unable to solve</p>