File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Problem with Update in MS Access Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Problem with Update in MS Access" Watch "Problem with Update in MS Access" New topic

Problem with Update in MS Access

Robyn Lynn

Joined: Jan 10, 2005
Posts: 7
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.

Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1082


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 ]

Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Robyn Lynn

Joined: Jan 10, 2005
Posts: 7
That's it!! I had done a partial copy & paste from an insert statement and didn't notice the 'and's.

I agree. Here's the link:
subject: Problem with Update in MS Access
It's not a secret anymore!