1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

jsp to Delete data from database wont work

Discussion in 'JSP' started by Dave1816, Dec 17, 2010.

  1. Dave1816

    Dave1816 New Member

    Joined:
    Dec 17, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hello can im new to Jsp and trying to delete data in a database using JSP. everything works fine except the data dose not delete :nonod: I have posted the code below if any 1 can help me. Thanks
    HTML:
    <html>
    <head>
    <title>Delete Question
    </title>
    </head>
    
    <body>
    <%
    
    int nID1;
     if (request.getParameter("nID") == null) {
    
    } else {
     String sQuestID = request.getParameter("nID"); 
    
    
     nID1 =  Integer.parseInt(sQuestID);
    
    
    %>
    <!-- the % tag below is what is called a scriptlet tag - allows java to be embedded in the jsp -->
    <%@ page import="java.sql.*" %>
    <%@ page import="java.util.*" %>
    
    <%
    
    
    // creates and initialises the JDBC-ODBC bridge driver
    	// NB this driver is designated as "experimental" and not recommended for commercial use!
    	Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
    
    	// note that we give the name of the local directory here! --> "nas1/" segment below
    	// will need changing if this page is moved!
    	String sHere = getServletContext().getRealPath("/au003022/jsp/bare2/JSP-FAQ-assignment.accdb");
    
    	// builds the connection string - makes it easier to print it for checking purposes
    	String sConn = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" + sHere + ";";
    
    // makes the connection with the database
    	Connection cnJDBC = DriverManager.getConnection(sConn);
    
    	// gets ready to send a SQL command down our connection
    	Statement stJDBC = cnJDBC.createStatement();
    
    
    	// Allows us to check our SQL statement and see that it is well formed
    	String sSQL = "Delete FROM tblFAQ WHERE ID='" + nID1 + "';";	
    	//out.print("Debug:<br />" + sSQL + "<hr />");
    
    //ResultSet rs = stJDBC.executeUpdate(sSQL);
    
    }
    
    //response.sendRedirect("logmain.jsp");
    
    
    
    
    %>
    </table>
    
    </body>
    </html>
     
    Last edited by a moderator: Dec 19, 2010

Share This Page