0

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?

Attachments 1.jpg 328.06 KB
2
Contributors
1
Reply
9
Views
3 Years
Discussion Span
Last Post by stultuske
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.