Robtyketto 0 Light Poster

Greetings,

I have 2 JSP files and a bean which are collectively used to delete a record from an access database.

They run without errors, however the only value from the form that is required, that is passed as a parameter to the bean is Null (debugging showed value is null).

The jsp file (wk465682DeleteFAQ)allows the user to enter a value to used be in an SQL statement to delete a record and also displays all current records on ANOTHER form.

When the button is pressed it then callsl the 2nd JSP file (wk465682DeleteFAQBean) which feeds the values from the first jsp form values into the bean.

The below code shows an extract from wk465682DeleteFAQ showing the form thats contains the value to be used within the bean:-

<FORM NAME ="deletefaqs" ACTION="wk465682DeleteFAQbean.jsp" METHOD="POST"><PRE>
  Id: <INPUT TYPE="text NAME="faqId">
<BR><BR>
<input type="submit"  value="Delete FAQ" size="8">
</FORM>

This then calls (wk465682DeleteFAQBean see code below where the value of faqId is displayed onscreen as null (added debug line):-

<%@ page language="java" contentType="text/html" %>
<HTML>
<HEAD><TITLE>Delete FAQ</TITLE></HEAD>
<BODY>

<%-- create an instance of the Delete JavaBean 
and give it the id name of 'FAQ' --%>
<jsp:useBean id="deletefaqs" class="robsbeans.DeleteFAQ" />

<%-- call the bean instance's setter method to assign values from
the html form properties  --%>
<jsp:setProperty name="deletefaqs" property="*"/>
<li>Print DeleteFAQ<jsp:getProperty name="deletefaqs" property="faqId" />

<%-- call the bean instances method to update the database --%>
<% deletefaqs.updateDatabaseforDelete(); %>

<%--forward action to pass control to the new page --%>

<%-- jsp:forward page="wk465682DeleteFAQ.jsp"/> --%>

</BODY>
</HTML>

Finally the java bean code :-

package robsbeans;
import java.sql.*;

public class DeleteFAQ
{
  private String faqId;
  
  // setter method
  public void setfaqId(String faqId){ this.faqId=faqId; } 

  // getter method returns value of the bean properties
  public String getfaqId() { return faqId; }
 

public void updateDatabaseforDelete(){
   
  try{
     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
//     Connection conn = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver 
//  (*.mdb)};DBQ=C:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/jw5/guestbook2.mdb;");
  
     Connection conn = DriverManager.getConnection("jdbc:odbc:FAQ"); 

     java.sql.Statement statement = conn.createStatement();

     //statement.executeUpdate("DELETE * FROM FAQ");

     statement.executeUpdate("DELETE * FROM FAQ WHERE Id = '" + faqId + "'");


   if (statement != null)
        statement.close();
   if (conn != null)
        conn.close();
    }
    catch(Exception e) { System.out.println("My error: " + e);}
  }
    
}

Can anyone pointout why the faqId value is null?
Hope this makes sense.

Cheers
Rob

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.