This week's book giveaways are in the AI and JavaScript forums.
We're giving away four copies each of GANs in Action and WebAssembly in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of GANs in ActionE this week in the AI forum
or WebAssembly in Action in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Joe Ess
  • salvin francis
  • fred rosenberger

Problem with Update in MS Access

Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to update a single row in an Access (2003) table. When I execute the statement, although it seems to execute without errors, the first column after the 'set' always results in '-1' in the database column (except for the primary key when I added 'EmployeeID = EmployeeID' after the set, which results in '0'. I have tried multiple ways of running the statement (the latest is below) and nothing helps. I also checked all of the values before running the statement and the values are correct. How would I write this so it will work?


con = DriverManager.getConnection("jdbc dbc:TimeRep");

//Update requested employee
String sql ="UPDATE Employee SET " +
"EmployeeFirstName = '" + firstName + "' AND " +
"EmployeeLastName = '" + lastName + "' AND " +
"LoginName = '" + loginName + "' AND " +
"Active = '" + active + "' " +
"WHERE EmployeeID = ? ";
stmt = con.prepareStatement(sql);
//stmt.setString(1, firstName);
//stmt.setString(2, lastName);
//stmt.setString(3, loginName);
//stmt.setString(4, active);
stmt.setString(1, emplId);
int numRows = stmt.executeUpdate();

numRows = 1 each time.

Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am not sure I understood your problem correctly.

Did you check what sql you are forming in your code, As you mentioned there is no error , could you check if you are not supressing any exception.
the code you posted here will result in a sql like

but a update sql should be like this

make sure you have valid update sql and no exception is supressed

[ May 06, 2005: Message edited by: Shailesh Chandra ]
Robyn Lynn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's it!! I had done a partial copy & paste from an insert statement and didn't notice the 'and's.

Good night. Drive safely. Here's a tiny ad for the road:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!