I'm a newbie to Java and I cant quite get my head around why it seems most integers appears to be formatted as strings and then later have to be parsed.
The code below, passes in the autonumber table field Id value named faqId which in the HTML code the Input type is "Int"
Expand|Select|Wrap|Line Numbers
- <FORM NAME ="deletefaqs" ACTION="wk465682DeleteFAQbean.jsp" METHOD="POST"><PRE>
- Id: <INPUT TYPE="Int" NAME="faqId">
- <BR><BR>
- <input type="submit" value="Delete FAQ" size="8">
- </FORM>
Expand|Select|Wrap|Line Numbers
- <%-- create an instance of the Delete JavaBean and give it the id name of 'deletefaqs' --%>
- <jsp:useBean id="deletefaqs" class="robsbeans.DeleteFAQ" scope="request" />
- <%-- call the bean instance's setter method to assign values from the html form properties --%>
- <jsp:setProperty name="deletefaqs" property="*" />
Expand|Select|Wrap|Line Numbers
- <%-- call the bean instances method to update the database --%>
- <% deletefaqs.updateDatabaseforDelete(); %>
Its runs and doesnt delete anything, I've printed out the value of faqId and it does print the value as it appears on the form i.e. its not NULL
Expand|Select|Wrap|Line Numbers
- package robsbeans;
- import java.sql.*;
- import java.io.*;
- public class DeleteFAQ
- {
- private String faqId;
- // setter method
- public void setfaqId(String InputfaqId){ faqId = InputfaqId; }
- // getter method returns value of the bean properties
- public String getfaqId() { return faqId; }
- public void updateDatabaseforDelete() {
- Connection conn1 = null, conn2 = null;
- try {
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
- conn1 = DriverManager.getConnection("jdbc:odbc:FAQ");
- }
- catch (Exception e1)
- {
- try
- {
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
- conn2 = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver*.mdb)};DBQ=C:/ProgramFiles/Apache Software Foundation/Tomcat6.0/webapps/2008-sem2/wk465682/FAQ.mdb");
- }
- catch (Exception e2) {System.out.print(e2);}
- }
- Connection conn;
- if(conn1 == null) conn = conn2;
- else conn = conn1;
- try {
- java.sql.Statement statement = conn.createStatement();
- String myquery ="DELETE * FROM FAQ WHERE Id = ? ";
- PreparedStatement mystatement = conn.prepareStatement(myquery);
- mystatement.setInt(1,Integer.parseInt(faqId));
- if (statement != null)
- statement.close();
- if (conn != null)
- conn.close();
- }
- catch (Exception e3) {System.out.print(e3);}
- }
- }