Results 1 to 2 of 2
  1. #1
    dannynoogen is offline Member
    Join Date
    May 2013
    Posts
    1
    Rep Power
    0

    Default showMessage dialog problem and update help

    I need help with this update code, I can't figure out how to get it to work.

    UserInterface
    Java Code:
                                            case 7: //update a Coilover	
    					coilNumber = JOptionPane.showInputDialog (null, "What is the Part's Number?", "Part Enquiry", JOptionPane.INFORMATION_MESSAGE);
    					try {
    						Coilovers c = (Coilovers) carpart.executeUpdate (new Coilovers (coilNumber.trim()));
    		 				int response = JOptionPane.showConfirmDialog (null, c + "\nAre you sure you want to update this record?\n", "Confirm Update?",                               
                                                    JOptionPane.YES_NO_OPTION);
    						if (response == JOptionPane.YES_OPTION) {
    							try {
    								carpart.updateConfirmed (carpart.find (c));
    								carpart.sort(); // removing shouldn't alter the order, but sort it just in case!!
    							}
    							catch (NotFoundException nfe) {
    								JOptionPane.showMessageDialog (null, "Part not found - please check Part Number", "Not Found",           
                                                            JOptionPane.INFORMATION_MESSAGE);
    							}
    							catch (SQLException se) {
    								JOptionPane.showMessageDialog (null, "ERROR in databaser", "DATABASE ERROR", JOptionPane.ERROR_MESSAGE);
    							}
    						} else {
    							// Employee record not deleted
    							JOptionPane.showMessageDialog (null, "The Part Record has NOT been Updated", "Not Updated", 
                                                            JOptionPane.INFORMATION_MESSAGE);
    						}
    					}
    					catch (NotFoundException nfe){
    						JOptionPane.showMessageDialog (null, "Part not found - please check Part Number", "Not Found", JOptionPane.INFORMATION_MESSAGE);
    					}
    					break;
    DataStorage
    Java Code:
                    public CarParts executeUpdate (CarParts cp) throws NotFoundException {
    		int index = find (cp);
    		if (index < 0) {
    			throw new NotFoundException ();
    		} else {
    			cp = dStore.get (index);
    		}
    		return cp;
    	        }
    	        public void updateConfirmed (int index) throws NotFoundException, SQLException {
    		GeneralDBAccess gdba = new GeneralDBAccess();
    		gdba.update (dStore.get (index)); // remove Person from the database ...
    		dStore.remove (index); // ... and then from ArrayList if no Exceptions are thrown
    GeneralDBAccess
    Java Code:
                            public void update (CarParts aPerson) throws NotFoundException, SQLException {
    		        if (aPerson instanceof Coilovers) {
    			Coilovers anEmployee = (Coilovers) aPerson;
    				// retrieve the customer attribute values
    			String partName = anEmployee.getPartName();
    			String amountOwed = (anEmployee.getAmountOwed());
    			String heightAdjustable = (anEmployee.getHeightAdjustable());
    			String damperAdjustable = anEmployee.getDamperAdjustable();
    			String coilNumber = (anEmployee.getCoilNumber());
    				// define the SQL query statement using the employee number key
    			String sqlUpdate = "UPDATE CoiloversTable " +
    								 " SET partName = '" + partName + "', " +
    								 " amountOwed = '" + amountOwed + "', " +
    								 " heightAdjustable = '" + heightAdjustable + "', " +
    								 " damperAdjustable = '" + damperAdjustable + "', " +
    								 " WHERE coilNumber = '" + coilNumber + "'";
    				// see if this customer already exists in the database
    				// NotFoundException & SQLException are thrown by find method
    			find ("Coilovers", coilNumber);
    					// if found, execute the SQL update statement
    			aStatement.executeUpdate (sqlUpdate);
    		} else if (aPerson instanceof Exhaust) {
    				// code for processing Supplier goes here
    			if (aPerson instanceof Exhaust) {
    				Exhaust anEmployee = (Exhaust) aPerson;
    					// retrieve the customer attribute values
    				String partName = anEmployee.getPartName();
    				String amountOwed = (anEmployee.getAmountOwed());
    				String material = (anEmployee.getMaterial());
    				String size = anEmployee.getSize();
    				String exhaustNumber = (anEmployee.getExhaustNumber());
    					// define the SQL query statement using the employee number key
    				String sqlUpdate = "UPDATE ExhaustTable " +
    									 " SET partName = '" + partName + "', " +
    									 " amountOwed = '" + amountOwed + "', " +
    									 " material = '" + material + "', " +
    									 " size = '" + size + "', " +
    									 " WHERE exhaustNumber = '" + exhaustNumber + "'";
    		} // end if
    	} // end update()
    Last edited by dannynoogen; 05-23-2013 at 02:23 PM. Reason: Figured out showMessage problem, just need help on update.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default Re: showMessage dialog problem and update help

    The questions I asked you in the other forum still stand.

    Crossposted: Update problem
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Problem with Looping input dialog
    By kiraichi in forum New To Java
    Replies: 3
    Last Post: 02-11-2012, 09:14 PM
  2. Problem creating dialog box
    By SeanC in forum New To Java
    Replies: 2
    Last Post: 08-13-2010, 05:38 PM
  3. save dialog problem
    By masa in forum AWT / Swing
    Replies: 2
    Last Post: 03-06-2009, 12:41 AM
  4. Replies: 18
    Last Post: 11-22-2008, 05:25 PM
  5. Problem in dialog
    By Sarinam in forum New To Java
    Replies: 5
    Last Post: 07-12-2008, 11:38 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •