Results 1 to 3 of 3
  1. #1
    Manas Das is offline Member
    Join Date
    Jan 2009
    Posts
    8
    Rep Power
    0

    Default Deleting rows from a database using JSP

    The code for deleting rows from a database is as follows:
    <%!
    Connection con;
    Statement st;
    ResultSet rs;
    int count=1;
    public void jspInit()
    {
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    con=DriverManager.getConnection("jdbc:odbc:manas", "System","manas");
    st=con.createStatement();
    rs=st.executeQuery("SELECT ROLL,BOOKID FROM LIBUCE WHERE ROLL=? AND BOOKID=?");
    }
    catch(Exception e)
    {
    System.out.println(e);
    }
    }
    public void jspDestroy()
    {
    try
    {
    st.close();
    con.close();
    rs.close();
    }
    catch(SQLException e)
    {
    e.printStackTrace();
    }
    }
    %>
    <%
    if((rs.getInt(2)==Integer.parseInt("t7"))&&(rs.get String(5)=="t8"))
    {
    do
    {
    rs.deleteRow();
    count++;
    }
    while(rs.next());
    }
    %>
    <html>
    <body bgcolor=green>
    <font size=6><%=count%> BOOK RETURNED SUCCESSFULLY.</font><BR><BR>
    <H1>ONE MORE BOOK TO RETURN.<BR><BR>
    </H1></body></html>

    i want to know what is the problem with this code.and which other code can be used.
    please reply soon.

  2. #2
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

    Default

    do you think select statement can delete record from database?

    you can try
    Java Code:
    int rows = st.executeUpdate("delete ...");
    if rows == 0, no record deleted

  3. #3
    neeraj.singh is offline Member
    Join Date
    Feb 2009
    Location
    Delhi
    Posts
    63
    Rep Power
    0

    Default

    to delete a row execute a query for it...
    rs.delete will delete that row from the rs only... not from the table

Similar Threads

  1. How to get the no. of rows in a resultset
    By baskar.nitt in forum New To Java
    Replies: 5
    Last Post: 09-19-2008, 01:30 PM
  2. Deleting All rows in the JTable
    By surot in forum New To Java
    Replies: 1
    Last Post: 04-16-2008, 10:44 AM
  3. Replies: 0
    Last Post: 02-09-2008, 08:31 PM
  4. Fetching rows from DB
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-06-2008, 09:23 AM
  5. Replies: 1
    Last Post: 08-08-2007, 01:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •