public static Vector<Integer> getValuesInVector(String query) throws SQLException {
    Vector<Integer> vc = new Vector<Integer>();

    ResultSet rs = Utilfunctions.executeQuery(query);
    while (rs.next()) vc.add(rs.getInt(1));

    return vc;
  }
 public static int getClassCode(String classString) throws SQLException {
   ResultSet rs =
       Utilfunctions.executeQuery(
           "SELECT classCode FROM class WHERE CONCAT(course,' ',dept,' ',year,' - ',section) = '"
               + classString
               + "'");
   rs.next();
   return rs.getInt(1);
 }
 public static void populateComboBoxwithQuery(JComboBox ComboBox, String Query)
     throws SQLException {
   ComboBox.removeAllItems();
   ResultSet result = Utilfunctions.executeQuery(Query);
   try {
     while (result.next() != false) {
       ComboBox.addItem(result.getString(1));
     }
   } catch (Exception e) {
     // Logger.getLogger(DayWisePeriodConfigChooseForm.class.getName()).log(Level.SEVERE, null, e);
     JOptionPane.showMessageDialog(null, e);
   }
 }
  public static int executeUpdate(String query) {
    int rowsAffected = 0;
    try {
      Class.forName("com.mysql.jdbc.Driver");
      String dbpwd = Utilfunctions.getDbConfig("password");
      if (con == null)
        con = DriverManager.getConnection("jdbc:mysql://localhost:3306/schedulepro", "root", dbpwd);
      PreparedStatement statement;
      statement = con.prepareStatement(query);

      rowsAffected = statement.executeUpdate();
    } catch (Exception e) {
      JOptionPane.showMessageDialog(null, e);
    }
    return rowsAffected;
  }
  public static int insertWithGeneratedKey(String query) {
    int lastInsertId = 0;
    try {
      Class.forName("com.mysql.jdbc.Driver");
      String dbpwd = Utilfunctions.getDbConfig("password");
      if (con == null)
        con = DriverManager.getConnection("jdbc:mysql://localhost:3306/schedulepro", "root", dbpwd);

      PreparedStatement statement = con.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
      statement.executeUpdate();

      ResultSet keys = statement.getGeneratedKeys();
      keys.next();
      lastInsertId = keys.getInt(1);

      return lastInsertId;
    } catch (Exception e) {
      JOptionPane.showMessageDialog(null, e);
    }
    return lastInsertId;
  }
  public static ResultSet executeQuery(String query) {

    try {
      try {
        Class.forName("com.mysql.jdbc.Driver");
      } catch (ClassNotFoundException ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage());
      }
      String dbpwd = Utilfunctions.getDbConfig("password");
      if (con == null)
        con = DriverManager.getConnection("jdbc:mysql://localhost:3306/schedulepro", "root", dbpwd);

      PreparedStatement statement = con.prepareStatement(query);
      result = statement.executeQuery();

    } catch (SQLException e) {
      // JOptionPane.showMessageDialog(null, e.getMessage());
      Logger.getLogger(DayWisePeriodConfigChooseForm.class.getName()).log(Level.SEVERE, null, e);
    }

    return result;
  }