• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What am I doing wrong?

 
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi. I'm trying to write a program that updates a table on SQL server. When I hardcode a ref number into my select statement and update it, it seems to work ok. But when I select all of the records from the table and try to update them, it doesn't update a darn thing. I've looked at it for a very long time trying to figure out what stupid mistakes I made, but can't find what I'm doing wrong. I was hoping someone could look at this code and help me out a bit??

Thanks for any help!!!

What I'm trying to do is trying to take pos. 3-4 of the customer code field(user5), check if they're blank(if so it's OK), if it's not blank, I want to move the value of those two positions to the beginning of the fields and fill the rest with blanks.
[ June 28, 2002: Message edited by: Jennifer Sohl ]
[ June 28, 2002: Message edited by: Dirk Schreckmann ]
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jennifer
The first thing that comes to mind is the fact that you're using the same Statment object to do both of your queries. If you use a Statement object and get a ResultSet back from a query then executing another query on that statement closes the current ResultSet. So at best your update would only work once, because after the ResultSet is closed. Does it update the first one that needs to be updated?
I'll take a look at the rest of it now but I wanted to tell you that first.
I looked at the rest of it and ust wanted to make sure you know that variable last2 will only be getting 1 character when the replace method is run. replace goes from the start postion to the last position -1. So the line:
last2.replace(0,1, rs.getString(1).substring(2,4));
is only going to replace the character at position 0 in the StringBuffer. The same applys to the other times you use replace:
user5all.replace(0,9,rs.getString(1));
refno.replace(0,9, rs.getString(2));
both of those are going to get their first 8 characters replaced, if that's the wrong number of characters your replace statement wont get any matching rows so it wont replace anything.
I would put in some print lines to see if that code is getting executed at all and also, maybe create the SQL outside of the excuteUpdate method and then print it to see exactly what it looks like.
hope that helps
[ June 28, 2002: Message edited by: Dave Vick ]
 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dave,
Thanks for the help! I created a different statement object for my update and it worked beautifully. Except of course for my StringBuffers that needed a bit of tweaking. Need to read up on those a bit more.
You are my hero.
I think I'll go drink a beer to that!!
Thanks again!!!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic