Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Update problem

  1. #1
    Junior Member
    Join Date
    May 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Update problem

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

    UserInterface
    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
    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
    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()


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,529
    My Mood
    Hungover
    Thanks
    144
    Thanked 647 Times in 552 Posts

    Default Re: Update problem

    What does this code do? What exactly do you mean when you say it doesn't work?

    You'd be much better off posting an SSCCE that demonstrates the problem that we can copy and paste and run ourselves- posting your whole program is too much, but posting disconnected snippets is not enough. Make it easy for us to help you.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    May 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Update problem

    The program is a record kind of program where a user interface comes up, which is a menu with things like 1. Add a new Coilover, 2. Add a new Exhaust etc. After that there are input boxes that come up which ask about the coilover or exhaust and this information is then added into a Microsoft Access database. The update code is just to access the database and update the information already in there.

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,529
    My Mood
    Hungover
    Thanks
    144
    Thanked 647 Times in 552 Posts

    Default Re: Update problem

    Nevermind, looks like I'm wasting my time.

    This thread has been cross posted here:

    http://www.java-forums.org/new-java/74231-showmessage-dialog-problem-update-help.html

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting

    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Junior Member
    Join Date
    May 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Update problem

    I'm new to the forum, I didn't think that it was a problem. I just posted on another forum to see if other people would be able to help me with my problem. But I do understand now where you're coming from with the cross posting.

    Thanks for your time anyways, sorry if I wasted it.

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,529
    My Mood
    Hungover
    Thanks
    144
    Thanked 647 Times in 552 Posts

    Default Re: Update problem

    Quote Originally Posted by dannynoogen View Post
    I'm new to the forum, I didn't think that it was a problem. I just posted on another forum to see if other people would be able to help me with my problem.



    Thanks for your time anyways, sorry I wasted it.
    The reason it's so frustrating is that we have no way of knowing what help you've already received, so we might just be repeating information you already heard, or even answering a question that's already been solved. It's considered polite to at least provide links to anywhere you've crossposted, that way we can see what's already been said. We're doing this for free in our spare time, so it's aggravating when we take the time to answer a question just to find out that it's been answered 3 other places already.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    Junior Member
    Join Date
    May 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Update problem

    The reason it's so frustrating is that we have no way of knowing what help you've already received, so we might just be repeating information you already heard, or even answering a question that's already been solved. It's considered polite to at least provide links to anywhere you've crossposted, that way we can see what's already been said. We're doing this for free in our spare time, so it's aggravating when we take the time to answer a question just to find out that it's been answered 3 other places already.
    Yeah I understand now, I didn't think it was a problem when I first posted. Sorry about being inconsiderate

  8. #8
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Update problem

    Quote Originally Posted by dannynoogen View Post
    Yeah I understand now, I didn't think it was a problem when I first posted. Sorry about being inconsiderate
    Here is a link to the Announcements page with a few useful forum tips

Similar Threads

  1. Why, won't this update?
    By Jerba in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 5th, 2012, 10:06 PM
  2. [SOLVED] Problem with update table after inserting new values
    By justyStepi in forum JDBC & Databases
    Replies: 4
    Last Post: September 10th, 2012, 04:52 PM
  3. Restricted user problem with Java RE 7 Update 4
    By thetechguy in forum Java Theory & Questions
    Replies: 1
    Last Post: May 23rd, 2012, 03:33 PM
  4. Replies: 3
    Last Post: January 5th, 2012, 01:44 AM
  5. Problem with Java Update freezing application
    By banny7 in forum Java Theory & Questions
    Replies: 0
    Last Post: October 25th, 2011, 01:36 PM

Tags for this Thread