This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes SQL coding to add stock balance in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "SQL coding to add stock balance in JSP" Watch "SQL coding to add stock balance in JSP" New topic
Author

SQL coding to add stock balance in JSP

richardtham
Greenhorn

Joined: Nov 07, 2001
Posts: 4
I am facing some problem writing this SQL coding on adding
a stock balance record in JSP:
Below is an extract from my coding:

<html>
<head>
<title>Purchase A Stock Item</title>
</head>
<h1>Purchase A Stock Item</h1>
<body background="indtextb.jpg" bgcolor="#CCCCCC" text="#000000"
link="#3366CC"
vlink="#666666" alink="#996600">
<table border="1" width="400">
<tr>
<td><b>Item ID</b></td><td><b>Item Name</b></td>
<td><b>Item Ref</b></td><td><b>Vendor ID</b></td> <td><b>Item
Cost</b></td> <td><b>Item
Markup</b></td>
<td><b>Selling Price</b></td><td><b>Item Quantity</b></td><td><b>Re-
order Quantity</b></td>
<td><b>Description</b></td> <td><b>Action To Perform</b></td>
</tr>
<%@ page language="java" import="java.sql.*" %>
<body>
<form action="idbpurchase.jsp">
<input name="ItemID" type="text" width="30">
<input type="submit" value="Enter A Item ID To Purchase">
</form>
<% String ItemID;
ItemID = request.getParameter("ItemID");
if (ItemID == null) {
%>

<%
}

else


Class.forName("org.gjt.mm.mysql.Driver");

Connection myConn = DriverManager.getConnection("jdbc:mysql:///stock");
Statement stmt = myConn.createStatement();
String sql = "SELECT * FROM ITEM WHERE ItemID=" + ItemID;
ResultSet rs = stmt.executeQuery(sql);

if (rs != null) {

while (rs.next()) {
String ItemID2 = rs.getString("ItemID");
String IName2 = rs.getString("IName");
String IRef2 = rs.getString("IRef");
String VendorID2 = rs.getString("VendorID");
String ICost2 = rs.getString("ICost");
String IMarkup2 = rs.getString("IMarkup");
String ISellp2 = rs.getString("ISellp");
String IQty2 = rs.getString("IQty");

String ReQty2 = rs.getString("ReQty");
String IDesc2 = rs.getString("IDesc");


%>
<tr>
<td><%= ItemID2 %></td>
<td><%= IName2 %></td>
<td><%= IRef2 %> </td>
<td><%= VendorID2 %> </td>
<td><%= ICost2 %></td>
<td><%= IMarkup2 %></td>
<td><%= ISellp2 %> </td>
<td><%= IQty2 %> </td>

<td><%= ReQty2 %></td>
<td><%= IDesc2 %></td>

<td><a href='imodproc2purchase.jsp?ItemID2=<%= ItemID2 %>'>confirm
purchase ?</a></td>
</tr>

<%

} /* of while */
} /* of if */

stmt.close();

myConn.close();
%>
</table>
</table>
<a href="icontrol.html">Go back to admin control</a>
</body>
</html>

******************************************
<title>
Purchase A Stock Item
</title>
</head>
<%@ page language="java" import="java.sql.*" %>
<body>
<body background="indtextb.jpg" bgcolor="#CCCCCC" text="#000000"
link="#3366CC"
vlink="#666666" alink="#996600">
<h1>Purchase A Stock Item</h1>
<form method="post" action="iupdpurchase.jsp">
<table border="1" width="400">

<tr>
<td><b>Quantity to Purchase:</b></td><td><input name="Qtypurchase"
type="text"
width="4"</td>
</tr>

<%
Class.forName("org.gjt.mm.mysql.Driver");
Connection myConn = DriverManager.getConnection("jdbc:mysql:///stock");

Statement stmt = myConn.createStatement();

%>


<tr>
<td colspan="2">
<center>
<input name="pagemode" type="hidden" value="submit">
<input type="submit" value="Enter Quantity To Purchase">
</center>
</td>
</tr>
<%
stmt.close();
myConn.close();
%>
</table>
</form>
<a href="icontrol.html">Go back to admin control</a>
</body>
</html>

*********************************************************************
<html>
<head>
<title>
Purchase A Stock Item Processing
</title>
<body background="indtextb.jpg" bgcolor="#CCCCCC" text="#000000"
link="#3366CC"
vlink="#666666" alink="#996600">
</head>
<%@ page language="java" import="java.sql.*" %>
<body>
<%
Class.forName("org.gjt.mm.mysql.Driver");
Connection myConn = DriverManager.getConnection("jdbc:mysql:///stock");
String ItemID4 = request.getParameter("ItemID");
String IQty4 = request.getParameter("IQty3");

Statement stmt = myConn.createStatement();
int rowsAffected = stmt.executeUpdate("add Qtypurchase into IQty from
item where ItemID=" +
ItemID4);
if (rowsAffected == 1)
{
%>
<h1>Successful Update of Purchase Item</h1>
The stock item has been modified.
<p>
<a href="idbquery.jsp">See all stock items</a><br>

<a href="icontrol.html">Go back to control center</a>
<% }
else
{
%>
<h1>Sorry, purchase update has failed.</h1>
<a href="icontrol.html">Go back to control center</a>
<%
}
stmt.close();
myConn.close();
%>
</body>
</html>

Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
This topic has been closed as it is a duplicate of a post in the JDBC forum.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
 
 
subject: SQL coding to add stock balance in JSP
 
Similar Threads
Sorry For Throwing Lengthy Codes At This Site, But I Really Need Help
How To Convert a Servlet File to a JSP File
Storing of Data
Tomcat and Mysql Configuration
SQL coding to add stock balance in JSP