| Author |
Query
|
Roberto Favaro
Greenhorn
Joined: Mar 23, 2004
Posts: 24
|
|
Whats wrong with my String command.I cant figure out my quotes>i keep getting a syntax error public int amendProduct(int id, String name, double price) throws DaoException { Connection con = null; Statement stmt = null; int rows = 0; try { con = getConnection(); stmt = con.createStatement(); String command = "UPDATE Product SET item = " + id + " WHERE id = " + id + " name = '" + name + "'" + " price = " + price ; System.out.println(command); rows = stmt.executeUpdate(command); } catch(SQLException e) { throw new DaoException("amendProduct(): " + e.getMessage() ); } finally { try { if (stmt != null) stmt.close() ; if (con !=null) freeConnection(con); } catch(SQLException e) { throw new DaoException("amendProduct(): " + e.getMessage() ); } } System.out.println(rows); return rows; }
|
 |
Edwin Keeton
Ranch Hand
Joined: Jul 10, 2002
Posts: 214
|
|
It looks like you need to add some ANDs to your WHERE clause. "UPDATE Product SET item = " + id + " WHERE id = " + id + " AND name = " + name + " AND price = " + price
|
SCJP, SCWCD
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56521
|
|
|
Explore the PreparedStatement. Your life will improve.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Bob Rocks
Greenhorn
Joined: Oct 21, 2004
Posts: 23
|
|
|
yes, prepared statements make life a breeze! Special characters will never give you any problems, they put less strain on the DB, they are just altogether a wonderful thing!
|
 |
 |
|
|
subject: Query
|
|
|