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 5 of 5

Thread: Using executeUpdate Question

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Using executeUpdate Question

    I have an html page that allows me to enter some address values. These
    values get passed to a servlet which uses executeUpdate to try and update several columns in a microsoft access database. The problem that I am having is that if I enter 2 values from the Htlm page which gets passed to the servlet to update two columns the other colunns in the database also get wiped out which is not what I want. I just need to update 2 values and leave the remaining colums in the database untouched. The update code is below.


    r_updcnt = s.executeUpdate("update AddressInfo2 SET F_NAME='" +
    fname + "', L_NAME='" + lname + "', STREET_ADDRESS='" + addr + "' WHERE F_NAME='"+sfield+"'");


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Using executeUpdate Question

    The Update you posted updates all 4 columns - if you only need to update 2 columns, then create an update statement that only updates the 2 columns necessary. And for what its worth, I recommend using a PreparedStatement.

  3. #3
    Junior Member
    Join Date
    Jun 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Using executeUpdate Question

    copeg, thanks for the info that you mentioned using an update starement that updates 2 columns. But if I have 10 columns on the html page and they want to update 5 of the 10 columns one time nad the another time they want to update 3 different columns of the 10 then would i need to set up different updates one for each different set of conditions?.

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Using executeUpdate Question

    It sounds like you wish to have a single Servlet change its behavior based upon the input provided. If so, you need to check which parameters are set and vary your query based upon which parameters need updating

  5. #5
    Junior Member
    Join Date
    Jun 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Using executeUpdate Question

    copeg, I will try that..

    Thanks

Similar Threads

  1. executeUpdate Problem
    By moacirvidal in forum JDBC & Databases
    Replies: 4
    Last Post: May 22nd, 2012, 02:47 AM