Re: I want corect code for deletind data from database(SQL)



Lew wrote:
amit.chhodhary@xxxxxxxxx wrote:
selectedName = request.getParameter("Combo Box");

statement.executeUpdate("delete ID,PHONENAME from PHONE where
ID=(select ID from PHONE WHERE PHONENAME= +selectedName ) " );

I want corect code for deletind data from database(SQL);

Snippet:

private static final String SQL =
"delete ID,PHONENAME from PHONE where PHONENAME = ?";
Connection cxn = DriverManager.getConnection( dbUrl );
PreparedStatement ps = cxn.prepareStatement( SQL );
int nRows = ps.executeUpdate();

Program structure and exception handling are obviously omitted.

I think I would use:

private static final String SQL = "delete from PHONE where PHONENAME = ?";
Connection cxn = DriverManager.getConnection( dbUrl );
PreparedStatement ps = cxn.prepareStatement( SQL );
ps.setString(1, selectedName);
int nRows = ps.executeUpdate();

I think you would too.

Arne
.