JavaWeb期中Word文档格式.docx
《JavaWeb期中Word文档格式.docx》由会员分享,可在线阅读,更多相关《JavaWeb期中Word文档格式.docx(42页珍藏版)》请在冰点文库上搜索。
牛奶"
3"
3.5"
饮料"
120"
蒙牛"
insert
intoMerchInfo(MerchID,MerchName,importPrice,warehouseprice,categories,MerchNum,porfferName)values
112032"
酸酸乳"
2.5"
110"
伊利"
112052"
方便面"
2"
4"
生活类"
123"
康师傅"
112055"
面包"
7"
12"
甜品"
盼盼"
效果图:
2.搭建数据库连接环境,在工作项目下的src文件夹中,创建包名为cn.edu.jiu.db的包,在包内新建DBUtil.Java文件
代码如下:
packagecn.edu.jiu.db;
importjava.sql.*;
importjava.util.*;
publicclassDBUtil{
privateConnectionconn;
privateStatementstmt;
privateResultSetrs;
publicbooleangetConnection(){
booleanret=false;
try{
Class.forName("
com.mysql.jdbc.Driver"
Stringurl="
jdbc:
mysql:
//127.0.0.1:
3306/supermarket?
"
+"
&
useUnicode=true&
characterEncoding=gb2312"
;
Stringuser="
root"
Stringpassword="
conn=DriverManager.getConnection(url,user,password);
}catch(Exceptione){
e.printStackTrace();
}
returnret;
}
publicintexecuteUpdate(Stringsql){
intret=0;
getConnection();
stmt=conn.createStatement();
ret=stmt.executeUpdate(sql);
close();
publicResultSetexecuteQuery(Stringsql){
rs=stmt.executeQuery(sql);
returnrs;
publicvoidclose(){
if(rs!
=null)
rs.close();
if(stmt!
stmt.close();
if(conn!
=null&
!
conn.isClosed())
conn.close();
publicstaticvoidmain(String[]args){
}
2.首页界面index1.jsp
<
%@pagelanguage="
java"
import="
java.util.*"
pageEncoding="
gb2312"
%>
!
DOCTYPEHTMLPUBLIC"
-//W3C//DTDHTML4.01Transitional//EN"
>
html>
<
head>
<
title>
超市管理系统<
/title>
styletype="
text/css"
body{
background-image:
url(8.jpg);
background-repeat:
no-repeat;
/style>
/head>
body>
h3>
&
nbsp;
/h3>
<
strong>
超市<
/strong>
hr/>
p>
ahref="
product.jsp"
target="
mainFrame"
style="
font:
16"
>
物品总览<
/a>
/p>
ruku.jsp"
入库管理<
chuku.jsp"
出库管理<
add.jsp"
新增物品<
reduce.jsp"
删除物品<
change.jsp"
物品修改<
query.jsp"
货物查询<
br>
/body>
/html>
2.入库代码ruku.jsp
gbk"
%@pageimport="
java.sql.*"
url(5.jpg);
jsp:
useBeanid="
dbutil"
class="
cn.edu.jiu.db.DBUtil"
scope="
page"
/jsp:
useBean>
%
Stringsql="
select*frommerchinfo"
ResultSetrs=dbutil.executeQuery(sql);
%>
palign="
center"
物品入库<
(通过物品编号进行添加)<
tableborder="
1"
align="
tr>
th>
商品编号
/th>
入库价格
出库价格
商品名称
库存量
商品类别
供应商
/tr>
while(rs.next()){
%>
td>
%=rs.getInt("
MerchID"
)%>
/td>
importPrice"
warehouseprice"
%=rs.getString("
MerchName"
MerchNum"
categories"
porfferName"
}
dbutil.close();
/table>
formid="
form1"
name="
method="
post"
action="
ruku2.jsp"
label>
&
br/>
/label>
tablewidth="
292"
border="
<
tdwidth="
89"
物品编号:
187"
<
<
inputname="
idproduct"
type="
text"
id="
/>
新增量:
add_amount"
tdcolspan="
&
inputtype="
submit"
Submit"
value="
保存"
reset"
Submit2"
重置"
/form>
2.ruku2.jsp
request.setCharacterEncoding("
GB2312"
StringMerchID=request.getParameter("
StringMerchNum=request.getParameter("
select*frommerchinfowhereMerchID='
+MerchID
+"
'
if(rs.next()){
inti=rs.getInt("
inta=Integer.valueOf(MerchNum);
intk=i+a;
out.print(k);
Stringsql1;
sql1="
updateMerchinfosetMerchNum='
+k
whereMerchID='
+MerchID+"
intrst=dbutil.executeUpdate(sql1);
out.print(rst);
if(rst>
0)
response.sendRedirect("
else
out.print("
失败"
}else
out.print("
dbutil.close();
3.出库代码chuku.jsp
url(1.jpg);
&
销售量:
4.chuku2.jsp
request.setCharacterEncoding("
StringMerchID=request.getParameter("
StringMerchNum=request.getParameter("
Stringsql="
+"
ResultSetrs=dbutil.executeQuery(sql);
if(rs.next()){
inti=rs.getInt("
inta=Integer.valueOf(MerchNum);
intk=i-a;
Stringsql1;
sql1="
intrst=dbutil.executeUpdate(sql1);
if(rst>
response.sendRedirect("
else
}else
out.print("
dbutil.close();
5增加物品.add.jsp
%@pagecontentType="
text/html;
charset=gbk"
--