what iam trying to do is get field parameter and run mysql query to update(decrement) value from field quantity, can any one tell me how to do that?

<form method="post">

<table class="bordered">
    <thead>

    <tr>
        <th>No</th>        
        <th>Drug Name</th>
        <th>Strength</th>
        <th>Quantity</th>
        <th>Dis Qty</th>            
    </tr>
    </thead>

     <% try {

String query="select * from drugs";

Statement stmt=conn.createStatement(); ResultSet rs=stmt.executeQuery(query); while(rs.next()) {

%>    <tr>     <td><%=rs.getInt("drugid") %></td>     <td><%=rs.getString("drugname") %></td>     <td><%=rs.getString("strength") %></td>    <td><%=rs.getInt("drugquant") %></td>    <td><INPUT TYPE="TEXT" NAME="getint" SIZE="7">
       <INPUT TYPE="SUBMIT" VALUE="Dispense" NAME="B1"></td>    </tr>


        <%


} %> </table>
    <%
    rs.close();
    stmt.close();
    conn.close();
    } catch(Exception e) {
    e.printStackTrace();
    }


![enter image description here][1]

%>

</form>

I tryed to use code similar to this but it doesnt work for me :(

<%
String getint = request.getParameter("getint");
String getsize = "";
// check if Update button is clicked
if(request.getParameter("B1") != null) {
    // get what user enterd in intbox
    getint = request.getParameter("getint");
    // DEBUG
    PreparedStatement pstmt4;
    pstmt4 = conn.prepareStatement("UPDATE drugs SET drugquant=drugquant - "+getint+" WHERE drugid=1");

    pstmt4.executeUpdate();
}

%>

any one could help?

firstly, remove all your java code from your jsp file and put it in a servlet, it'll make it a lot easier to read/maintain.
your problem is that you are trying to use the connection after you've closed it.
it's a bit the same as stepping through a wooden door right after you slammed it shut: asking for a head ache.

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.