This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
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


Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Problem with Update in MS Access" Watch "Problem with Update in MS Access" New topic
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: 1082

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!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with Update in MS Access
 
It's not a secret anymore!