| Author |
Problem with Update in MS Access
|
Robyn Lynn
Greenhorn
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? ------------------- 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!
|
 |
Shailesh Chandra
Ranch Hand
Joined: Aug 13, 2004
Posts: 1076
|
|
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 ]
|
Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
|
 |
Robyn Lynn
Greenhorn
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. Thanks!!
|
 |
 |
|
|
subject: Problem with Update in MS Access
|
|
|