11 Replies Latest reply: Jul 25, 2008 11:44 PM by 807589 RSS

    update DB

    807589
      hey guys going brain dead here and was wondering if I could get a hand with the syntax to get this working.
      btndel.addActionListener(new ActionListener()  // update user button
      
                {
      
                     public void actionPerformed(ActionEvent e)
      
                     {
      
                          //shows an update statement
      
                          Connection con = data.getConnection();
      
                          String query = "UPDATE INTO tbluser (password) VALUES ('"+txtPass.getText()+"') WHERE (email) VALUES='"+txtmail.getText()+"'+(name) VALUES='"txtName.getText()"')";
      
                          Statement state;
      
                          int i;
      
      
      
                          try
      
                          {
      
                               state = con.createStatement();//this is generic done for every sql statement
      
                               i = state.executeUpdate(query);
      
                               System.out.println(query);
      
      
      
                               //otherwise ResultSet result = state.executeQuery(query); 
      
                          }
      
                          catch(Exception ex)
      
                          {
      
                               System.out.println("insert failed "+ex);
      
                          }
      
                          txtmail.setText("");
      
                          txtPass.setText("");
      
                          txtName.setText("");
      
                          txtlist.setText("");
      
                          repaint();
      
                     }
      
                });
        • 1. Re: update DB
          masijade
          Okay then, the most important point about this is first, and foremost, don't mix your GUI code and your business logic/persistence layer/data model code.
          • 2. Re: update DB
            807589
            Although I see several flaws in your code, it is always helpful if you share the error message and the stacktrace with us.
            • 3. Re: update DB
              DrClap
              You might be asking about the format of your SQL update statement, I suppose. It looks wrong to me, although it's extremely hard to see because Firefox puts it in a box with a scroll bar at the bottom and I have to look at the SQL, scroll down to the scroll bar, scroll right a bit, scroll back up to the SQL, and so on. Besides your SQL isn't real SQL, it's a Java string concatenation. And it doesn't help that your code doesn't start until two thirds of the way across the little box because you put so much whitespace in the left side.

              Anyway, some advice:

              1. If you are having trouble with your SQL, look at your SQL. Don't look at some Java code which is stuffed with plus signs and both kinds of quotes, look at your SQL.

              2. Use a PreparedStatement so you don't have to write and debug the aforesaid Java code.
              • 4. Re: update DB
                807589
                thank you. running right now
                • 5. Re: update DB
                  masijade
                  Okay, ignore me, but then don't complain when your GUI hangs for a while everytime you push a button.

                  Edit: or when a minor change to your GUI, or your data model, causes sweeping changes to be made in your code.
                  • 6. Re: update DB
                    807589
                    masijade. wrote:
                    Okay then, the most important point about this is first, and foremost, don't mix your GUI code and your business logic/persistence layer/data model code.
                    Indeed. I'd rather take some raw chicken and some cooked chicken and then make hand puppets
                    out of them and use them to illustrate scenes from "The Postman Always Rings Twice" then
                    eat the chicken than mix layers like that.
                    • 7. Re: update DB
                      807589
                      DrClap wrote:
                      scroll, scroll and scroll
                      I'm happy with the touchpad of my laptop which allows horizontal scrolling of the area under the pointer.
                      • 8. Re: update DB
                        807589
                        DrLaszloJamf wrote:
                        masijade. wrote:
                        Okay then, the most important point about this is first, and foremost, don't mix your GUI code and your business logic/persistence layer/data model code.
                        Indeed. I'd rather take some raw chicken and some cooked chicken and then make hand puppets
                        out of them and use them to illustrate scenes from "The Postman Always Rings Twice" then
                        eat the chicken than mix layers like that.
                        How about if Roman Polanski directed your chicken-hand-puppets in a scene-by-scene remake of 'O Lucky Man', and Carrot Top was the key grip? Jeez, he'd be forever showing you hilarious gags with the chicken, who knows where he'd stick it, or rub it, or fondle it? And of course, Carrot Top would be just as bad
                        • 9. Re: update DB
                          DrClap
                          BalusC wrote:
                          DrClap wrote:
                          scroll, scroll and scroll
                          I'm happy with the touchpad of my laptop which allows horizontal scrolling of the area under the pointer.
                          Unfortunately mine doesn't. It just acts a second mouse.
                          • 10. Re: update DB
                            807589
                            masijade. wrote:
                            Okay, ignore me, but then don't complain when your GUI hangs for a while everytime you push a button.

                            Edit: or when a minor change to your GUI, or your data model, causes sweeping changes to be made in your code.
                            I wish I knew what to make of that and I wouldn't be ignoring it. If you couldn't tell I'm not that adverse in java.
                            • 11. Re: update DB
                              807589
                              DrLaszloJamf wrote:
                              masijade. wrote:
                              Okay then, the most important point about this is first, and foremost, don't mix your GUI code and your business logic/persistence layer/data model code.
                              Indeed. I'd rather take some raw chicken and some cooked chicken and then make hand puppets
                              out of them and use them to illustrate scenes from "The Postman Always Rings Twice" then
                              eat the chicken than mix layers like that.
                              wtf?? lol. I needed a good laugh. I want some of what you're smoking err um taking.