aspose file tools*
The moose likes JDBC and the fly likes Query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Query" Watch "Query" New topic
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: 61770
    
  67

Explore the PreparedStatement. Your life will improve.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by 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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Query