Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Delete Statement

Status
Not open for further replies.

faiyth

Programmer
Nov 22, 2002
19
US
I have a form with 2 buttons. The names of the buttons are selected. The values are delete or update. Now this is the code below. I just want to be able to delete and if the button delete is pushed a confirm to be shown. If yes is pressed on the confirm, then delete..

CODE:

If(request.getParameter("selected")=="Delete") {
out.println(&quot;<form name=confirm method=Post action=lstdog02.jsp>&quot;);
out.println(&quot;Are you sure you want to delete this record?&quot;);
out.println(&quot;<br><input type=submit name=confirm value=yes>&quot;);
out.println(&quot;<input type=submit name=confirm value=no>&quot;);
}

Else If(request.getParameter(&quot;confirm&quot;)==&quot;yes&quot;) {
String sql1 = &quot;Delete From K9Manager where intakeno = &quot; + request.getParameter(&quot;f_intakeno&quot;);
PreparedStatement ps0 = db.createPreparedStatement(sql1); }

ERRORS:
Syntax: &quot;;&quot; inserted to complete BlockStatements
Syntax: new expected instead of this token
Syntax: ; expected instead of this token
Syntax: &quot;;&quot; inserted to complete ExpressionStatement


I can't find anywhere where I left out a ;.. :) Please help
 
A couple of problems:

Never use '==' to compare strings. It compares memory addresses, NOT string equality. It will often create hard to track down bugs.

Instead, use:

if (&quot;Delete&quot;.equals(request.getParameter(&quot;selected&quot;)))

Also, hopefully you aren't capitalizing your If and Else statements as in your example code--this won't work. &quot;if&quot; and &quot;else&quot; are keywords in java, &quot;If&quot; and &quot;Else&quot; aren't.

I also don't see where you've declared the object 'db' that you refer to...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top