title: Inserting values into database table using static method when button is clicked
body: <p>I'm working on a project that is used to gather customer information and store it into a table called "BOOKINGS" The table has columns "CUSTOMERNAME","HOLIDAYNAME", "MAGICIAN", and "TIMESTAMP" </p>
  
  <p>I have a class called "DatabaseConnection" that establishes a connection to the database that has the bookings table. This class has functioned as expected in other areas of the project. Within the class I have a static method called "addBooking"</p>
  
  <p>I have a GUI class (using Netbeans GUI generator) that has an actionperformed method. Here is the code for the actionperformed method and the addBooking method...</p>
  
  <pre><code>private void bookButtonActionPerformed(java.awt.event.ActionEvent evt) {                                           
  
  
      String customerName = customerNameText.getText();
      String magician = (String)magicianCombo.getSelectedItem();
      String holiday = (String)holidayCombo.getSelectedItem();
  
      customerNameText.setText(null);
  
      try {
          DatabaseConnection.addBooking(customerName, holiday, magician);
      } catch (SQLException ex) {
          Logger.getLogger(GUI1Frame.class.getName()).log(Level.SEVERE, null, ex);
      }
  }        
  </code></pre>
  
  <p>I didn't send any information for timestamp because I haven't figured that part out just yet. Here is the code for the addBooking method in the DatabaseConnection class. </p>
  
  <pre><code>public static void addBooking(String name, String holiday, String employee) throws SQLException { 
      stmt.execute("INSERT INTO BOOKINGS (CUSTOMERNAME, HOLIDAYNAME, MAGICIAN) VALUES ('"+name+"','"+holiday+"','"+employee+"')");
  }          
  </code></pre>
  
  <p>Clicking the button is supposed to get information from a textbox (Customer name), information from a combo box (holiday) and information from another combo box (employee). I can't figure out why it isn't working, but whenever the button is clicked the program freezes for about 10-15 seconds and then continues, but no information is entered in the table. Any help would be appreciated, thank you. </p>
  
  <p>EDIT: Added code for the rest of DatabaseConnection class</p>
  
  <pre><code>public class DatabaseConnection {
  String host = "jdbc:derby://localhost:1527/MagicianAgent";
  String username = "java";
  String password = "java";
  
  static Connection con = null;
  ResultSet rs = null;
  static Statement stmt;
  
  DatabaseConnection() { 
      try { 
          con = DriverManager.getConnection(host, username, password);
          stmt = con.createStatement();
      }
      catch(SQLException err) { 
          System.out.println(err.getMessage());
      }
  }
  
  public ResultSet getRS(String sql) { 
      try {
          rs = stmt.executeQuery(sql);
      }
      catch(SQLException err) { 
          System.out.println(err.getMessage());
      }
      return rs;
  }
  </code></pre>
  
  <p>EDIT 2: This is some code I have in the main method. </p>
  
  <pre><code>    Holiday holidayList = new Holiday();
      Magician magicianNames = new Magician();
      arrays = magicianNames.getMagicianNames();
      for(int e = 0; e &lt; arrays.size(); e++ ) { 
          magicianCombo.addItem(arrays.get(e));
      }
      arrays = holidayList.getHolidayList();
      for(int e = 0; e &lt; arrays.size(); e++) { 
          holidayCombo.addItem(arrays.get(e));
      }
  </code></pre>
  
  <p>In the Holiday and Magician constructors, they access the database through DatabaseConnection and store the values of holiday names and magician names in an ArrayList. Then the ArrayList items are added to the combo box until the end of the ArrayList is reached. I'm not sure if this would change the behavior of anything, but I thought I should add it. </p>