Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void deleteRec(JComboBox code)
- {
- boolean flag1 = false;
- boolean flag2 = false;
- try
- {
- Class.forName("com.mysql.jdbc.Driver");
- Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/stock","root","");
- String query = "SELECT stockCode FROM stock_transaction WHERE stockCode = '" + code.getSelectedItem() + "'";
- Statement stmt = con.createStatement();
- ResultSet rs = stmt.executeQuery(query);
- while(rs.next())
- {
- }
- con.close();
- }
- catch(Exception e)
- {
- flag1 = true;
- }
- try
- {
- Class.forName("com.mysql.jdbc.Driver");
- Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/stock","root","");
- String query = "SELECT stockCode FROM stock_master WHERE stockCode = '" + code.getSelectedItem() + "'";
- Statement stmt = con.createStatement();
- ResultSet rs = stmt.executeQuery(query);
- while(rs.next())
- {
- }
- con.close();
- }
- catch(Exception e)
- {
- flag2 = true;
- }
- if(flag1 == true && flag2 == true)
- {
- try
- {
- Class.forName("com.mysql.jdbc.Driver");
- Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/stock","root","");
- PreparedStatement st = con.prepareStatement("DELETE FROM stock_master WHERE stockCode = ?");
- st.setString(1, (String)code.getSelectedItem());
- st.executeUpdate();
- con.close();
- }
- catch(Exception e)
- {
- JOptionPane.showMessageDialog(null, "This code is already in the transaction table and cannot be deleted ");
- }
- }
- }
- buttonDelete.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- deleteRec(comboBoxStockCode);
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement