This site requires JavaScript, please enable it in your browser!
Greenfoot back
divinity
divinity wrote ...

2018/1/22

error with delete record

divinity divinity

2018/1/22

#
hi pple how are you all, I am doing a car rental management system project, not a school assignment but something i am practicing on. I am currently some codes it will allow the program to delete any record that may not be relevant anymore but for some reason, I am getting an error with the delete record and also another error I am experiencing is with the UIManage.getSystemLookandFeel method. can some explain it to me and how to go about fixing it . here is the codes.
package Rental_Services;

import java.sql.SQLException;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.table.DefaultTableCellRenderer;
/**
 *
 * @author luana
 */
public class listofstaff extends javax.swing.JFrame {
    
   boolean addRecord = false;
   
   private  void clearInputBoxesstatic() {
       jtxt_empIDNum.setText("");
       jtxt_fullName.setText("");
       cboGender.setSelectedItem("");
       jtxt_depart.setText("");
       jtxt_position.setText("");
       jtxt_salary.setText("");
       
}
   private void addNew() throws SQLException{
       String sql_stmt = "INSERT INTO employees (fullName, gender, department, position, salary)";
       sql_stmt += " VALUES ('" + jtxt_fullName.getText() + "','" + cboGender.getSelectedItem().toString() + "','" + jtxt_depart.getText() + "','" + jtxt_position.getText() + "','" + jtxt_salary.getText() + "')";
       
       DBUtilities dbu= new DBUtilities();
       dbu.ExecuteSQLStatement(sql_stmt);
       
   }
   private void updateRecord() throws SQLException{
       String sql_stmt = "UPDATE employees SET full_name = '" + jtxt_fullName.getText() + "'";
       sql_stmt +=",gender = '" +  cboGender.getSelectedItem().toString() + "'";
       sql_stmt += ", department" + jtxt_depart.getText() + "'";
       sql_stmt += ",position" + jtxt_position.getText() + "'";
       sql_stmt += ",salary"  +  jtxt_salary.getText() +  "'";
       sql_stmt += "WHERE empIDNum = " + jtxt_empIDNum.getText() + "'";
       
       DBUtilities dbu = new DBUtilities();
       dbu.ExecuteSQLStatement(sql_stmt);
       
   }
   private void deletRecord() throws SQLException{
       String sql_stmt = "DELET FROM employess WHERE employees_IDNum = " + jtxt_empIDNum.getText() + "'";
       
       DBUtilities dbu = new DBUtilities();
       dbu.ExecuteSQLStatement(sql_stmt);
       
   }
   private void loadRecord() throws SQLException{
       String sql_stmt = " SELECT * FROM  employees; ";
       
       ResultSetTableModel rstm = new ResultSetTableModel(sql_stmt);
       jTab1.setModel(rstm);
       
        jTab1.getSelectionModel().addListSelectionListener((ListSelectionEvent event) -> {
            try {
                if (jTab1.getSelectedRow() >= 0) {
                    Object employee_id = jTab1.getValueAt(jTab1.getSelectedRow(), 0);
                    Object full_name = jTab1.getValueAt(jTab1.getSelectedRow(), 1);
                    Object gender = jTab1.getValueAt(jTab1.getSelectedRow(), 2);
                    Object department = jTab1.getValueAt(jTab1.getSelectedRow(), 3);
                    Object position = jTab1.getValueAt(jTab1.getSelectedRow(), 4);
                    Object salary = jTab1.getValueAt(jTab1.getSelectedRow(), 5);

                    jtxt_empIDNum.setText(employee_id.toString());
                    jtxt_fullName.setText(full_name.toString());
                    cboGender.setSelectedItem(gender.toString());
                    jtxt_depart.setText(department.toString());
                    jtxt_position.setText(position.toString());
                    jtxt_salary.setText(salary.toString());
                }
            } catch (Exception ex) {
                //System.out.println(ex.getMessage());
            }
        });
          
        DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer();
        rightRenderer.setHorizontalAlignment(SwingConstants.LEFT);
        jTab1.getColumnModel().getColumn(0).setCellRenderer(rightRenderer);
        
        
   }  
          
    public listofstaff() {
        initComponents();
    }

       
       
    private void jbtnAddNewActionPerformed(java.awt.event.ActionEvent evt) {                                           
        addRecord = true;
        
        //clearInputBoxes();
        
        jtxt_fullName.requestFocus();
    }                                          

    private void jbtnUpdateActionPerformed(java.awt.event.ActionEvent evt) {                                           
       int dialogResult = JOptionPane.showConfirmDialog(null, "Are you sure you want to update this record?", "confirm update record", JOptionPane.YES_NO_OPTION);
        
                if(dialogResult == JOptionPane.YES_NO_OPTION)
                {
                    try{
                        
                        if(addRecord == true)
                        {
                            addNew();
                        }
                        else
                        {
                            updateRecord();
                        }
                        addRecord = false;
                         loadRecord();
                    }
                    catch(SQLException ex){
                        System.out.println(ex.getMessage());
                    }
                           
                }        
        
    }                                          

    private void jbtnDeleteActionPerformed(java.awt.event.ActionEvent evt) {                                           
       
        
        int dialogResult = JOptionPane.showConfirmDialog(null, "Are you sure you want to delete this record?");
        
                if(dialogResult == JOptionPane.YES_NO_OPTION)
                {
                    try
                    {
                         
                         //deleteRecord(); <---- this is the error
                         
                         loadRecord();
                    }
                    catch(SQLException ex)
                    {
                      
  System.out.println(ex.getMessage());
                    }
                           
                }    
    }      



this is the other error am getting
public class Employees {
    
   // set the system l & f
   try
   {
       UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());<---- the error is right here
   }
   catch(SQLException ex)
   {
       
   }
    
   Employees emp = new Employees();
                        
the error is: unreported exception ClassNotFoundException; must be caught or declared to be thrown what does this mean and how do i fix this
danpost danpost

2018/1/22

#
It means that the look and feel could not be set to the class that the string value returned by the get...ClassName method referred to. You can easily prevent the error by adding another 'catch' clause for ClassNotFoundException. You can try to set a different look and feel within that clause or just deal with having the current look and feel by not adding any code to that clause.
Yehuda Yehuda

2018/1/23

#
There is a tutorial on look and feel here.
divinity divinity

2018/1/23

#
thank danpost and yehuda
You need to login to post a reply.