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">

        <th>Drug Name</th>
        <th>Dis Qty</th>            

     <% 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>
    } catch(Exception e) {

![enter image description here][1]



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");



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, learning, and sharing knowledge.