Where to Create JDBC Connection in JFrame Java Swing-The object is already closed H2 Database

By Suryam Jy

I am developing a POS related application using Java Swing GUI, it’s all related with Sql quires for most of the JButton to perform retrieving, Inserting,Updating data. when ever i am trying to close the connection for every Prepared Statement or Statement operation once completed and trying to work with another Operation it is showing The object is already closed

I am Creating the connection in the constructor and using it in entire Frame any mistake here please Help

Here is my Code:`

public SalesTasks() {
    try {
        Class.forName("org.h2.Driver");
        connection=DriverManager.getConnection("jdbc:h2:~/test","sa", "");
    } catch (ClassNotFoundException | SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setBounds(140, 100, 1084, 600);
    contentPane = new JPanel();
    contentPane.setLocation(-376, -389);
    contentPane.setBackground(Color.WHITE);
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    JButton purchase_button = new JButton("");
    purchase_button.setBounds(60, 118, 112, 89);
    purchase_button.setBackground(Color.WHITE);
    Image photo=new ImageIcon(this.getClass().getResource("/purchase.png")).getImage();
    purchase_button.setIcon(new ImageIcon(photo));
    purchase_button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            falseCommands();
            tip_label.setVisible(false);
            purchases_panel.setVisible(true);
            //sales_panel.setVisible(false);
            //reports_panel.setVisible(false);
        }
    });
    contentPane.setLayout(null);
    JPanel panel = new JPanel();
    panel.setBounds(563, 118, 438, 401);
    contentPane.add(panel);
    panel.setLayout(null);
    JButton btnNewButton_1 = new JButton("List P D C");
    btnNewButton_1.setBounds(26, 367, 129, 23);
    panel.add(btnNewButton_1);
    JLabel lblTotalStockValue = new JLabel("Total Stock Value");
    lblTotalStockValue.setBounds(26, 21, 83, 28);
    panel.add(lblTotalStockValue);
    JLabel lblTotalSalesYesterday = new JLabel("Total Sales ");
    lblTotalSalesYesterday.setBounds(26, 63, 83, 28);
    panel.add(lblTotalSalesYesterday);
    JLabel lblTotalCollectioon = new JLabel("Purchases");
    lblTotalCollectioon.setBounds(26, 106, 83, 28);
    panel.add(lblTotalCollectioon);
    JLabel lblTotalOutstanding = new JLabel("Collection");
    lblTotalOutstanding.setBounds(26, 145, 83, 28);
    panel.add(lblTotalOutstanding);
    JLabel lblNewLabel = new JLabel("Payments");
    lblNewLabel.setBounds(26, 184, 83, 28);
    panel.add(lblNewLabel);
    stock_value = new JTextField();
    stock_value.setEditable(false);
    stock_value.setBounds(119, 25, 153, 23);
    panel.add(stock_value);
    stock_value.setColumns(10);
    total_sales = new JTextField();
    total_sales.setEditable(false);
    total_sales.setColumns(10);
    total_sales.setBounds(119, 67, 153, 23);
    panel.add(total_sales);
    total_purchases = new JTextField();
    total_purchases.setEditable(false);
    total_purchases.setColumns(10);
    total_purchases.setBounds(119, 110, 153, 23);
    panel.add(total_purchases);
    total_collections = new JTextField();
    total_collections.setEditable(false);
    total_collections.setColumns(10);
    total_collections.setBounds(119, 145, 153, 23);
    panel.add(total_collections);
    total_payments = new JTextField();
    total_payments.setEditable(false);
    total_payments.setColumns(10);
    total_payments.setBounds(119, 184, 153, 23);
    panel.add(total_payments);
    btnNewButton_1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            ListOfPendingDebitCredit lpdc=new ListOfPendingDebitCredit();
            lpdc.debitCreditPendingApproval();
            lpdc.setVisible(true);
        }
    });
    contentPane.add(purchase_button);
    JButton sales_button = new JButton("");
    sales_button.setBounds(60, 221, 112, 89);
    sales_button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            falseCommands();
            tip_label.setVisible(false);
            //task_combobox.setVisible(true);
            sales_panel.setVisible(true);
        }
    });
    Image photo_5=new ImageIcon(this.getClass().getResource("/sales.png")).getImage();
    sales_button.setIcon(new ImageIcon(photo_5));
    sales_button.setBackground(Color.WHITE);
    contentPane.add(sales_button);
    JButton accounts_button = new JButton("");
    accounts_button.setBounds(60, 324, 112, 89);
    accounts_button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            falseCommands();
            tip_label.setVisible(false);
            accounts_panel_one.setVisible(true);
        }
    });
    Image photo_6=new ImageIcon(this.getClass().getResource("/accounts.png")).getImage();
    accounts_button.setIcon(new ImageIcon(photo_6));
    accounts_button.setBackground(Color.WHITE);
    contentPane.add(accounts_button);
    user_name_display = new JLabel("");
    user_name_display.setBounds(60, 59, 401, 30);
    user_name_display.setFont(new Font("Tahoma", Font.PLAIN, 25));
    contentPane.add(user_name_display);
    JLabel lblPurchases = new JLabel("Purchases");
    lblPurchases.setBounds(61, 100, 79, 19);
    lblPurchases.setFont(new Font("Tahoma", Font.PLAIN, 11));
    contentPane.add(lblPurchases);
    JLabel lblSales = new JLabel("Sales");
    lblSales.setBounds(62, 207, 57, 14);
    lblSales.setFont(new Font("Tahoma", Font.PLAIN, 11));
    contentPane.add(lblSales);
    JLabel lblAccounts = new JLabel("Accounts");
    lblAccounts.setBounds(93, 297, 57, 19);
    contentPane.add(lblAccounts);
    purchases_panel = new JPanel();
    purchases_panel.setBounds(182, 114, 79, 93);
    purchases_panel.setBackground(Color.WHITE);
    purchases_panel.setVisible(false);
    contentPane.add(purchases_panel);
    purchases_panel.setLayout(null);
    JButton btnAddProducts = new JButton("<html>Existing<br> Vendor</html>");
    btnAddProducts.setHorizontalAlignment(SwingConstants.LEADING);
    btnAddProducts.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            select_orgname.removeAllItems();
            purchase_panel_combobox_button.setVisible(true);
            select_orgname.setVisible(true);
            select_org.setVisible(true);
            companyNames();
        }
    });
    btnAddProducts.setBackground(Color.WHITE);
    btnAddProducts.setBounds(0, 6, 77, 41);
    purchases_panel.add(btnAddProducts);
    JButton btnHistory = new JButton("<html>New<br>Vendor</html>");
    btnHistory.setHorizontalAlignment(SwingConstants.LEADING);
    btnHistory.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            Party_Information pi = new Party_Information();
            pi.type_of_entry_to_party_info.setText("Enter Vendor Details");
            pi.introduction_panel.setVisible(false);
            purchase_panel_combobox_button.setVisible(false);
            pi.setVisible(true);
        }
    });
    btnHistory.setBackground(Color.WHITE);
    btnHistory.setBounds(0, 50, 77, 41);
    purchases_panel.add(btnHistory);
    rerurn_panel_one = new JPanel();
    rerurn_panel_one.setBounds(261, 219, 292, 93);
    rerurn_panel_one.setVisible(false);
    rerurn_panel_one.setBackground(new Color(255, 255, 255));
    contentPane.add(rerurn_panel_one);
    rerurn_panel_one.setLayout(null);
    type_of_retutn = new JComboBox();
    type_of_retutn.addItem("Saleable");
    type_of_retutn.addItem("Breakage/Damage");
    type_of_retutn.addItem("Expired");
    type_of_retutn.setBounds(3, 4, 185, 41);
    rerurn_panel_one.add(type_of_retutn);
    JButton btnOk = new JButton("Proceed");
    btnOk.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Returns rs=new Returns();
            String getType=(String)type_of_retutn.getSelectedItem();
            rs.get_return_type.setText(getType);
            rs.setVisible(true);
        }
    });
    btnOk.setBounds(191, 4, 91, 42);
    rerurn_panel_one.add(btnOk);
    JButton btnCrStatus = new JButton("Credit Note Status");
    btnCrStatus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            CreditNoteInformation cni = new CreditNoteInformation();
            cni.cni_credit_note_number.setEditable(true);
            cni.setVisible(true);
        }
    });
    btnCrStatus.setBounds(3, 49, 279, 40);
    rerurn_panel_one.add(btnCrStatus);
    JButton btnClose = new JButton("Close");
    btnClose.setBounds(913, 528, 89, 23);
    btnClose.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    });
    contentPane.add(btnClose);
    sales_panel = new JPanel();
    sales_panel.setBounds(182, 223, 79, 88);
    sales_panel.setVisible(false);
    sales_panel.setBackground(Color.WHITE);
    contentPane.add(sales_panel);
    sales_panel.setLayout(null);
    invoice_button = new JButton("Invoice");
    invoice_button.setBounds(0, 0, 76, 44);
    sales_panel.add(invoice_button);
    returns_button = new JButton("Returns");
    returns_button.setBounds(0, 46, 76, 39);
    sales_panel.add(returns_button);
            returns_button.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    //invoice_button.setVisible(false);
                    //purchases_panel.setVisible(false);
                    sales_panel_two.setVisible(false);
                    rerurn_panel_one.setVisible(true);
                }
            });
            returns_button.setBackground(Color.WHITE);
            accounts_panel_one = new JPanel();
            accounts_panel_one.setBounds(181, 324, 83, 89);
            accounts_panel_one.setVisible(false);
            accounts_panel_one.setBackground(Color.WHITE);
            contentPane.add(accounts_panel_one);
            accounts_panel_one.setLayout(null);
            JButton btnPayments = new JButton("Collection");
            btnPayments.setBounds(0, 1, 79, 41);
            accounts_panel_one.add(btnPayments);
            JButton btnPayments_1 = new JButton("Payments");
            btnPayments_1.setBounds(0, 44, 79, 43);
            accounts_panel_one.add(btnPayments_1);
            btnPayments_1.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    orgDropdown();

// accounts_payments_panel_one.setVisible(true);
// accounts_receipts_panel_two.setVisible(false);

                    accounts_payments_panel_one.setVisible(false);
                    accounts_receipts_panel_two.setVisible(true);
                }
            });
            sales_panel_two = new JPanel();
            sales_panel_two.setBounds(264, 222, 79, 89);
            contentPane.add(sales_panel_two);
            sales_panel_two.setVisible(false);
            sales_panel_two.setBackground(Color.WHITE);
            sales_panel_two.setLayout(null);
            JButton btnexistingParty = new JButton("<html>Existing<br> Party</html>");
            btnexistingParty.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    new SellInvoice().setVisible(true);
                }
            });
            btnexistingParty.setHorizontalAlignment(SwingConstants.LEADING);
            btnexistingParty.setBackground(Color.WHITE);
            btnexistingParty.setBounds(0, 2, 77, 43);
            sales_panel_two.add(btnexistingParty);
            JButton btnnewparty = new JButton("<html>New<br>Party</html>");
            btnnewparty.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    Party_Information pi = new Party_Information();
                    pi.introduction_panel.setVisible(false);
                    pi.type_of_entry_to_party_info.setText("Please Enter Customer Details");
                    pi.setVisible(true);
                }
            });
            btnnewparty.setHorizontalAlignment(SwingConstants.LEADING);
            btnnewparty.setBackground(Color.WHITE);
            btnnewparty.setBounds(0, 47, 77, 39);
            sales_panel_two.add(btnnewparty);
            JButton btnNewButton_2 = new JButton("Reports");
            btnNewButton_2.setBounds(60, 431, 112, 93);
            btnNewButton_2.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    falseCommands();
                    tip_label.setVisible(false);
                    reports_panel_one.setVisible(true);
                }
            });
            contentPane.add(btnNewButton_2);
            reports_panel_one = new JPanel();
            reports_panel_one.setVisible(false);
            reports_panel_one.setBounds(178, 431, 86, 93);
            reports_panel_one.setBackground(Color.WHITE);
            contentPane.add(reports_panel_one);
            reports_panel_one.setLayout(null);
            JButton btnStockAndSales = new JButton("<html>Stock &<br> Sales</html>");
            btnStockAndSales.setBounds(3, 3, 79, 43);
            reports_panel_one.add(btnStockAndSales);
            JButton btnpurchaseSales = new JButton("<html>Sales<br>Reports</html>");
            btnpurchaseSales.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    stock_and_sales_panel.setVisible(false);
                    task_combobox.setVisible(true);
                    date_panel_from_to.setVisible(true);
                }
            });
            btnpurchaseSales.setBounds(3, 48, 79, 42);
            reports_panel_one.add(btnpurchaseSales);
            stock_and_sales_panel = new JPanel();
            stock_and_sales_panel.setBounds(264, 424, 298, 108);
            contentPane.add(stock_and_sales_panel);
            stock_and_sales_panel.setVisible(false);
            stock_and_sales_panel.setBackground(new Color(255, 255, 255));
            stock_and_sales_panel.setLayout(null);
            month_sands = new JComboBox();
            month_sands.addItem("January");
            month_sands.addItem("February");
            month_sands.addItem("March");
            month_sands.addItem("April");
            month_sands.addItem("May");
            month_sands.addItem("June");
            month_sands.addItem("July");
            month_sands.addItem("August");
            month_sands.addItem("September");
            month_sands.addItem("October");
            month_sands.addItem("November");
            month_sands.addItem("December");
            month_sands.setBounds(6, 43, 129, 27);
            stock_and_sales_panel.add(month_sands);
            year_sands = new JComboBox();
            year_sands.addItem("2016");
            year_sands.addItem("2017");
            year_sands.addItem("2018");
            year_sands.addItem("2019");
            year_sands.addItem("2020");
            year_sands.addItem("2021");
            year_sands.addItem("2022");
            year_sands.addItem("2023");
            year_sands.addItem("2024");
            year_sands.addItem("2025");
            year_sands.addItem("2026");
            year_sands.addItem("2027");
            year_sands.addItem("2028");
            year_sands.addItem("2029");
            year_sands.addItem("2030");
            year_sands.addItem("2031");
            year_sands.addItem("2032");
            year_sands.addItem("2033");
            year_sands.addItem("2034");
            year_sands.addItem("2035");
            year_sands.addItem("2036");
            year_sands.addItem("2037");
            year_sands.addItem("2038");
            year_sands.addItem("2039");
            year_sands.addItem("2040");
            year_sands.addItem("2041");
            year_sands.setBounds(144, 43, 135, 27);
            stock_and_sales_panel.add(year_sands);
            JButton btnNewButton = new JButton("View");
            btnNewButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    StockAndSales sas=new StockAndSales();
                            String total_org_detail="select orgname,product, "
                                    + "sum(openingstock) as openingStock, "
                                    + "sum(receipts) as receipts, "
                                    + "sum(totalstock) totalstock, "
                                    + "sum(sales) as sales, sum(return) as "
                                    + "returns, sum(closingstock)as "
                                    + "closingstock from purchase_table where date between"
                                    + " ? and ? group by product order by orgname";
                    String stock_sales_report="select product, price,sellprice, "
                            + "sum(openingstock) as openingStock, sum(openingstock)*price as op_value, "
                            + "sum(receipts) as receipts,free, sum(receipts)*price as re_value, "
                            + "sum(totalstock) totalstock,sum(totalstock)*price as ts_value, "
                            + "sum(sales) as sales, sum(sales)*sellprice as s_value, "
                            + "sum(return) as returns,sum(return)*sellprice as rt_value, "
                            + "sum(closingstock)as closingstock, sum(closingstock)*price as cl_value  "
                            + "from purchase_table where date between ? and ? and orgname =? group by product,price";
                            String jan_sdate="-01-01";
                            String feb_sdate="-02-01";
                            String mar_sdate="-03-01";
                            String apr_sdate="-04-01";
                            String may_sdate="-05-01";
                            String jun_sdate="-06-01";
                            String jul_sdate="-07-01";
                            String aug_sdate="-08-01";
                            String sep_sdate="-09-01";
                            String oct_sdate="-10-01";
                            String nov_sdate="-11-01";
                            String dec_sdate="-12-01";
                            String jan_edate="-01-31";
                            String feb_edate="-02-28";
                            String m_febdate="-02-29";
                            String mar_edate="-03-31";
                            String apr_edate="-04-30";
                            String may_edate="-05-31";
                            String jun_edate="-06-30";
                            String jul_edate="-07-31";
                            String aug_edate="-08-31";
                            String sep_edate="-09-30";
                            String oct_edate="-10-31";
                            String nov_edate="-11-30";
                            String dec_edate="-12-31";
                            String date_one=year_sands.getSelectedItem()+mar_sdate; //
                            String date_two=year_sands.getSelectedItem()+mar_edate;
                            int leapYear = 2012;
                            while (leapYear <= 2050) {
                                leapYear = leapYear + 4;
                                if(leapYear==Integer.parseInt((String) year_sands.getSelectedItem()) &&
                                        month_sands.getSelectedItem().equals("February"))
                                {
                                    try {
                                        if(company_dropdown_sas.getSelectedItem().equals("TOTAL"))
                                        {
                                            try {
                                                String show_all_products=total_org_detail;
                                                PreparedStatement ps_shal=connection.prepareStatement(show_all_products);
                                                ps_shal.setString(1, year_sands.getSelectedItem()+feb_sdate);
                                                ps_shal.setString(2, year_sands.getSelectedItem()+m_febdate);
                                                ResultSet set_shal=ps_shal.executeQuery();
                                                sas.table_sas.setModel(DbUtils.resultSetToTableModel(set_shal));
                                                sas.show_month_year_sas.setText("TOTAL STOCK");
                                                sas.setVisible(true);
                                            } catch (Exception e2) {
                                                // TODO: handle exception
                                            }
                                            return;
                                        }
                                        String march_date_data=stock_sales_report;
                                        PreparedStatement statement = connection.prepareStatement(march_date_data);
                                        statement.setString(1, year_sands.getSelectedItem()+feb_sdate);
                                        statement.setString(2, year_sands.getSelectedItem()+m_febdate);
                                        statement.setString(3, (String)company_dropdown_sas.getSelectedItem());
                                        ResultSet set_nsas=statement.executeQuery();
                                        sas.table_sas.setModel(DbUtils.resultSetToTableModel(set_nsas));
                                        sas.show_month_year_sas.setText((String)company_dropdown_sas.getSelectedItem()+" -> "+(String)month_sands.getSelectedItem()+"  "+(String)year_sands.getSelectedItem());
                                        sas.setVisible(true);
                                        //JOptionPane.showMessageDialog(null, "While method sucessfully executed");
                                    } catch (Exception e2) {
                                        // TODO: handle exception
                                    }
                                  return;
                                }
                            }
                                try {
                                    if(company_dropdown_sas.getSelectedItem().equals("TOTAL"))
                                    {
                                        String show_all_products=total_org_detail;
                                        PreparedStatement ps_shal=connection.prepareStatement(show_all_products);
                                        if(month_sands.getSelectedItem().equals("January"))
                                        {
                                            ps_shal.setString(1, year_sands.getSelectedItem()+jan_sdate);
                                            ps_shal.setString(2, year_sands.getSelectedItem()+jan_edate);
                                        }
                                        if(month_sands.getSelectedItem().equals("February"))
                                        {
                                            ps_shal.setString(1, year_sands.getSelectedItem()+feb_sdate);
                                            ps_shal.setString(2, year_sands.getSelectedItem()+feb_edate);
                                        }
                                        if(month_sands.getSelectedItem().equals("March"))
                                        {
                                           ps_shal.setString(1, date_one);
                                           ps_shal.setString(2, date_two);
                                        }
                                        if(month_sands.getSelectedItem().equals("April"))
                                        {
                                            ps_shal.setString(1, year_sands.getSelectedItem()+apr_sdate);
                                            ps_shal.setString(2, year_sands.getSelectedItem()+apr_edate);
                                        }
                                        if(month_sands.getSelectedItem().equals("May"))
                                        {
                                            ps_shal.setString(1, year_sands.getSelectedItem()+may_sdate);
                                            ps_shal.setString(2, year_sands.getSelectedItem()+may_edate);
                                        }
                                        if(month_sands.getSelectedItem().equals("June"))
                                        {
                                            ps_shal.setString(1, year_sands.getSelectedItem()+jun_sdate);
                                            ps_shal.setString(2, year_sands.getSelectedItem()+jun_edate);
                                        }
                                        if(month_sands.getSelectedItem().equals("July"))
                                        {
                                            ps_shal.setString(1, year_sands.getSelectedItem()+jul_sdate);
                                            ps_shal.setString(2, year_sands.getSelectedItem()+jul_edate);
                                        }
                                        if(month_sands.getSelectedItem().equals("August"))
                                        {
                                            ps_shal.setString(1, year_sands.getSelectedItem()+aug_sdate);
                                            ps_shal.setString(2, year_sands.getSelectedItem()+aug_edate);
                                        }
                                        if(month_sands.getSelectedItem().equals("September"))
                                        {
                                            ps_shal.setString(1, year_sands.getSelectedItem()+sep_sdate);
                                            ps_shal.setString(2, year_sands.getSelectedItem()+sep_edate);
                                        }
                                        if(month_sands.getSelectedItem().equals("October"))
                                        {
                                            ps_shal.setString(1, year_sands.getSelectedItem()+oct_sdate);
                                            ps_shal.setString(2, year_sands.getSelectedItem()+oct_edate);
                                        }
                                        if(month_sands.getSelectedItem().equals("November"))
                                        {
                                            ps_shal.setString(1, year_sands.getSelectedItem()+nov_sdate);
                                            ps_shal.setString(2, year_sands.getSelectedItem()+nov_edate);
                                        }
                                        if(month_sands.getSelectedItem().equals("December"))
                                        {
                                            ps_shal.setString(1, year_sands.getSelectedItem()+dec_sdate);
                                            ps_shal.setString(2, year_sands.getSelectedItem()+dec_edate);
                                        }
                                        ResultSet set_shal=ps_shal.executeQuery();

// if(!set_shal.next())
// {
// JOptionPane.showMessageDialog(null, “No Data Found”);
// return;
// }

                                        sas.table_sas.setModel(DbUtils.resultSetToTableModel(set_shal));
                                        sas.show_month_year_sas.setText((String)company_dropdown_sas.getSelectedItem()+"  "+(String)month_sands.getSelectedItem()+"  "+(String)year_sands.getSelectedItem());
                                        sas.setVisible(true);
                                        return;
                                    }
                                    String march_date_data=stock_sales_report;
                                    PreparedStatement statement = connection.prepareStatement(march_date_data);
                                    if(month_sands.getSelectedItem().equals("January"))
                                    {
                                        statement.setString(1, year_sands.getSelectedItem()+jan_sdate);
                                        statement.setString(2, year_sands.getSelectedItem()+jan_edate);
                                        statement.setString(3, (String)company_dropdown_sas.getSelectedItem());
                                    }
                                    if(month_sands.getSelectedItem().equals("February"))
                                    {
                                        statement.setString(1, year_sands.getSelectedItem()+feb_sdate);
                                        statement.setString(2, year_sands.getSelectedItem()+feb_edate);
                                        statement.setString(3, (String)company_dropdown_sas.getSelectedItem());
                                    }
                                    if(month_sands.getSelectedItem().equals("March"))
                                    {
                                    statement.setString(1, date_one);
                                    statement.setString(2, date_two);
                                    statement.setString(3, (String)company_dropdown_sas.getSelectedItem());
                                    }
                                    if(month_sands.getSelectedItem().equals("April"))
                                    {
                                        statement.setString(1, year_sands.getSelectedItem()+apr_sdate);
                                        statement.setString(2, year_sands.getSelectedItem()+apr_edate);
                                        statement.setString(3, (String)company_dropdown_sas.getSelectedItem());
                                    }
                                    if(month_sands.getSelectedItem().equals("May"))
                                    {
                                        statement.setString(1, year_sands.getSelectedItem()+may_sdate);
                                        statement.setString(2, year_sands.getSelectedItem()+may_edate);
                                        statement.setString(3, (String)company_dropdown_sas.getSelectedItem());
                                    }
                                    if(month_sands.getSelectedItem().equals("June"))
                                    {
                                        statement.setString(1, year_sands.getSelectedItem()+jun_sdate);
                                        statement.setString(2, year_sands.getSelectedItem()+jun_edate);
                                        statement.setString(3, (String)company_dropdown_sas.getSelectedItem());
                                    }
                                    if(month_sands.getSelectedItem().equals("July"))
                                    {
                                        statement.setString(1, year_sands.getSelectedItem()+jul_sdate);
                                        statement.setString(2, year_sands.getSelectedItem()+jul_edate);
                                        statement.setString(3, (String)company_dropdown_sas.getSelectedItem());
                                    }
                                    if(month_sands.getSelectedItem().equals("August"))
                                    {
                                        statement.setString(1, year_sands.getSelectedItem()+aug_sdate);
                                        statement.setString(2, year_sands.getSelectedItem()+aug_edate);
                                        statement.setString(3, (String)company_dropdown_sas.getSelectedItem());
                                    }
                                    if(month_sands.getSelectedItem().equals("September"))
                                    {
                                        statement.setString(1, year_sands.getSelectedItem()+sep_sdate);
                                        statement.setString(2, year_sands.getSelectedItem()+sep_edate);
                                        statement.setString(3, (String)company_dropdown_sas.getSelectedItem());
                                    }
                                    if(month_sands.getSelectedItem().equals("October"))
                                    {
                                        statement.setString(1, year_sands.getSelectedItem()+oct_sdate);
                                        statement.setString(2, year_sands.getSelectedItem()+oct_edate);
                                        statement.setString(3, (String)company_dropdown_sas.getSelectedItem());
                                    }
                                    if(month_sands.getSelectedItem().equals("November"))
                                    {
                                        statement.setString(1, year_sands.getSelectedItem()+nov_sdate);
                                        statement.setString(2, year_sands.getSelectedItem()+nov_edate);
                                        statement.setString(3, (String)company_dropdown_sas.getSelectedItem());
                                    }
                                    if(month_sands.getSelectedItem().equals("December"))
                                    {
                                        statement.setString(1, year_sands.getSelectedItem()+dec_sdate);
                                        statement.setString(2, year_sands.getSelectedItem()+dec_edate);
                                        statement.setString(3, (String)company_dropdown_sas.getSelectedItem());
                                    }
                                    ResultSet set_sas=statement.executeQuery();

// if(!set.next())
// {
// JOptionPane.showMessageDialog(null, “No Data Available for Selected Month and Year”);
// return;
// }

                                    sas.table_sas.setModel(DbUtils.resultSetToTableModel(set_sas));
                                    sas.show_month_year_sas.setText((String)company_dropdown_sas.getSelectedItem()+"  "+(String)month_sands.getSelectedItem()+"  "+(String)year_sands.getSelectedItem());
                                    sas.setVisible(true);
                                } catch (Exception e2) {
                                    // TODO: handle exception
                                }
                }
            });`

Source: Stack Overflow

    

Share it with your friends!

    Fatal error: Uncaught Exception: 12: REST API is deprecated for versions v2.1 and higher (12) thrown in /home/content/19/9652219/html/wp-content/plugins/seo-facebook-comments/facebook/base_facebook.php on line 1273