title: Null Pointer Exception at Statement stmt = conn.CreateStatement. Am new to this, I cannot find a solution?
body: <p>The idea of this program is to connect to a database, using a graphical interface that gives the user options to to alter or update the database. It starts with the DriverManager connection, and methods are written to be called by JRadioButton options (Yes I am aware it is an unusual use of radio buttons). The GUI calls on the methods, but from these methods, despite creating the connection through driver manager, there seems to be a null pointer exception through conn still. I would be very grateful if someone could explain to me why this is still pointing to a null, rather than the DriverManager.getConnection?
  Thanks.</p>
  
  <pre><code>    public Connection getConnection() throws SQLException {
          try {
              Class.forName("com.mysql.jdbc.Driver");
  
              conn = DriverManager.getConnection("jdbc:mysql://localhost/Uni",
                      "resit", "summer1");
  
          } catch (Exception e) {
              System.err.println(e.getMessage());
              e.printStackTrace();
              System.exit(1);
          }
          return conn;
      }
  
      public static void main(String args[]) {
  </code></pre>
  
  <p>GUI works fine alone, but does not seem to connect to the database through the DriverManager Connection.</p>
  
  <pre><code>        Query myGUI = new Query();
  
      }
  
      private static void insertLecturer() throws SQLException {
          String a = JOptionPane.showInputDialog("Insert: LID");
          String b = JOptionPane.showInputDialog("Insert FirstName");
          String c = JOptionPane.showInputDialog("Insert LastName");
          String d = JOptionPane.showInputDialog("Insert Salary");
  </code></pre>
  
  <p>This line (below) is pointing to a null connection? But cannot understand or see why?</p>
  
  <pre><code>    Statement stmt = conn.createStatement();
          String sql = "INSERT INTO Lecturer VALUES " + "(" + a + " " + "'" + b
                  + "'" + " " + "'" + c + "'" + " " + d + ")" + ";";
          stmt.executeUpdate(sql);
  
      }
  </code></pre>
  
  <p>Using the ActionEvent from the GUI to call the SQL methods.<br>
          }</p>
  
  <pre><code>    public void actionPerformed(ActionEvent a) {
  
          if (a.getActionCommand() == first) {
              try {
                  insertLecturer();
              } catch (SQLException e) {
                  e.printStackTrace();
              }
          }
  </code></pre>