This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Svelte and Sapper in Action and have Mark Volkmann on-line!
See this thread for details.
Win a copy of Svelte and Sapper in Action this week 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 ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Problem with Update in MS Access

 
Greenhorn
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?

-------------------

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
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.


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

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

Shailesh
[ May 06, 2005: Message edited by: Shailesh Chandra ]
 
Robyn Lynn
Greenhorn
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.

Thanks!!
 
This will take every ounce of my mental strength! All for a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic