1. 程式人生 > >庫存物資管理系統

庫存物資管理系統

tint time() out implement sys tst 登錄 trac bsp

一、實驗思路

在數據庫中建立兩個表,flow表存放出入庫的單據,Warehouse表存放商品的信息。FlowBean類和WarehouseBean類處理所用到的變量;通過FlowDao類和WarehouseDao類進行連接;通com.servlet包中的類進行增刪改查的操作.

結構及數據庫表如下圖所示:

技術分享圖片 技術分享圖片

技術分享圖片

技術分享圖片

二、源代碼

(1)jsp文件

<%@ page language="java" contentType="text/html; charset=UTF-8"
      pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登錄界面</title>
</head>
<body>
<table width = "400" border ="0" height = "300" align = "center" cellpading ="0" style = "font-size:12px;color:#FFFFF;front-weight:bold">
<Tr height = "50" ><td>&nbsp;</td></Tr>
<tr>
   <td height = "200"><table width = "98%" border ="0" align = "center" cellpading = "0">
   <form name = "form1"  action = "addServlet" method = "post">
<tr>
<td>商品名稱:</td><td><input type="text" name="addname" /></td>
</tr>
<tr>
<td>生產廠家:</td><td><input type="text" name="addfactory" /></td>
</tr>
<tr>
<td>型號:</td><td><input type="text" name="addmodel" /></td>
</tr>
<tr>
<td>規格:</td><td><input type="text" name="addstandard" /></td>
</tr>
<tr>
<td>數量:</td><td><input type="text" name="addnumber" /></td>
</tr>
<tr>
<td>入庫單位名稱:</td><td><input type="text" name="adddanwei" /></td>
</tr>
<tr>
<td>送貨人姓名:</td><td><input type="text" name="addperson" /></td>
</tr>
<tr>
<td><input name = "login" type = "submit" id = "login" value = "提交" class
= "button"></td> </tr> </form> </table> </td> </tr> </table> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
      pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登錄界面</title>
</head>
<body>
<table width = "400" border ="0" height = "300" align = "center" cellpading ="0" style = "font-size:12px;color:#FFFFF;front-weight:bold">
<Tr height = "50" ><td>&nbsp;</td></Tr>
<tr>
   <td height = "200"><table width = "98%" border ="0" align = "center" cellpading = "0">
   <form name = "form1"  action = "AmendServlet" method = "post">
<tr>
<td>商品名稱:</td><td><input type="text" name="Amendname" /></td>
</tr>
<tr>
<td>生產廠家:</td><td><input type="text" name="Amendfactory" /></td>
</tr>
<tr>
<td>型號:</td><td><input type="text" name="Amendmodel" /></td>
</tr>
<tr>
<td>規格:</td><td><input type="text" name="Amendstandard" /></td>
</tr>
<tr>
<td>數量:</td><td><input type="text" name="Amendnumber" /></td>
</tr>
<tr>
<td>出庫單位名稱:</td><td><input type="text" name="Amenddanwei" /></td>
</tr>
<tr>
<td>提貨人姓名:</td><td><input type="text" name="Amendperson" /></td>
</tr>
<tr>
<td><input name = "login" type = "submit" id = "login" value = "提交" class
= "button"></td> </tr> </form> </table> </td> </tr> </table> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
      pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登錄界面</title>
</head>
<body>
<table width = "400" border ="0" height = "300" align = "center" cellpading ="0" style = "font-size:12px;color:#FFFFF;front-weight:bold">
<Tr height = "50" ><td>&nbsp;</td></Tr>
<tr>
   <td height = "200"><table width = "98%" border ="0" align = "center" cellpading = "0">
   <form name = "form2"  action = "AmendWareServlet" method = "post">
<tr>
<td>要修改商品的名稱:</td><td><input type="text" name="Amendname" /></td>
</tr>
<tr>
<td>改後商品名稱:</td><td><input type="text" name="amendname" /></td>
</tr>
<tr>
<td>生產廠家:</td><td><input type="text" name="amendfactory" /></td>
</tr>
<tr>
<td>型號:</td><td><input type="text" name="amendmodel" /></td>
</tr>
<tr>
<td>規格:</td><td><input type="text" name="amendstandard" /></td>
</tr>
<tr>
<td><input name = "login" type = "submit" id = "login" value = "保存" class
= "button"></td> </tr> </form> </table> </td> </tr>
<%@ page language="java" contentType="text/html; charset=UTF-8"
      pageEncoding="UTF-8"%>
      <%@page import="java.util.List" %>
      <%@page import="com.bean.WarehouseBean" %>
      <%@page import="com.dao.WarehouseDao" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登錄界面</title>
</head>
<body>
<table width = "400" border ="0" height = "300" align = "center" cellpading ="0" style = "font-size:12px;color:#FFFFF;front-weight:bold">
<Tr height = "50" ><td>&nbsp;</td></Tr>
<tr>
   <td height = "200"><table width = "98%" border ="0" align = "center" cellpading = "0">
   <form >
  <tr>
   <td>歡迎使用本系統</td>
  </tr>
  <tr>
  <%
    request.setCharacterEncoding("UTF-8");
    String name=request.getParameter("Selectname");
    WarehouseBean c=null;
    List<WarehouseBean> beans = WarehouseDao.select(name);
    for(int i=0;i<beans.size();i++)
    {
        c=beans.get(i);
        out.println("</br>");
        out.println("商品名稱="+c.getName()+",生產廠家="+c.getFactory()+",型號="+c.getModel()+",規格="+c.getStandard());
    }
  %>
  </tr>
  <tr>
  <td><a href="jiemian.jsp">返回</a></td>
  </tr>
  <tr>
  <td><a href="jieshu.jsp">結束</a></td>
  </tr>
 </form>
 </table>
 </td>
 </tr>
</table>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
      pageEncoding="UTF-8"%>
      <%@page import="java.util.List" %>
      <%@page import="com.bean.WarehouseBean" %>
      <%@page import="com.bean.FlowBean" %>
      <%@page import="com.dao.WarehouseDao" %>
      <%@page import="com.dao.FlowDao" %>
      <%@page import="java.sql.Timestamp" %>
      <%@page import="java.text.SimpleDateFormat" %>
      <%@page import="java.util.Date" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登錄界面</title>
</head>
<body>
<table width = "400" border ="0" height = "300" align = "center" cellpading ="0" style = "font-size:12px;color:#FFFFF;front-weight:bold">
<Tr height = "50" ><td>&nbsp;</td></Tr>
<tr>
   <td height = "200"><table width = "98%" border ="0" align = "center" cellpading = "0">
   <form >
  <tr>
   <td>歡迎使用本系統</td>
  </tr>
  <tr>
  <%
    request.setCharacterEncoding("UTF-8");
    String time1=request.getParameter("time1");
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date date = sdf.parse("2016-06-06 16:24:50");
    FlowBean c=null;
    int a=0;
    List<FlowBean> beans = FlowDao.select();
    a=beans.size();
    for(int i=0;i<beans.size();i++)
    {
        c=beans.get(i);
        if(c.getDate().getTime()>date.getTime())
        {out.println("</br>");
        out.println("商品名稱="+c.getName()+",生產廠家="+c.getFactory()+",型號="+c.getModel()+",規格="+c.getStandard());
        }

    }

  %>
  </tr>
  <tr>
  <td><a href="jiemian.jsp">返回</a></td>
  </tr>
  <tr>
  <td><a href="jieshu.jsp">結束</a></td>
  </tr>
 </form>
 </table>
 </td>
 </tr>
</table>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
      pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登錄界面</title>
</head>
<body>
<table width = "400" border ="0" height = "300" align = "center" cellpading ="0" style = "font-size:12px;color:#FFFFF;front-weight:bold">
<Tr height = "50" ><td>&nbsp;</td></Tr>
<tr>
   <td height = "200"><table width = "98%" border ="0" align = "center" cellpading = "0">
   <form name = "form1"  action = "DeleteWareServlet" method = "post">
<tr>
<td>請輸入要刪除的商品名稱:</td><td><input type="text" name="Deletename" /></td>
</tr>
<tr>
<td><input name = "login" type = "submit" id = "login" value = "提交" class = "button"></td>
</tr>
 </form>
 </table>
 </td>
 </tr>
</table>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
      pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登錄界面</title>
</head>
<body>
<table width = "400" border ="0" height = "300" align = "center" cellpading ="0" style = "font-size:12px;color:#FFFFF;front-weight:bold">
<Tr height = "50" ><td>&nbsp;</td></Tr>
<tr>
   <td height = "200"><table width = "98%" border ="0" align = "center" cellpading = "0">
   <form >
  <tr>
   <td>歡迎使用本系統</td>
  </tr>
  <tr>
   <td>請選擇功能:</td>
  </tr>
    <tr>
   <td><a href="addWare.jsp">商品增加</a></td>
  </tr>
    <tr>
   <td><a href="DeleteWare.jsp">商品刪除</a></td>
  </tr>
   <tr>
   <td><a href="AmendWare.jsp">商品修改</a></td>
  </tr>
     <tr>
   <td><a href="Selectware.jsp">商品查找</a></td>
  </tr>
  <tr>
   <td><a href="add.jsp">入庫</a></td>
  </tr>
  <tr>
   <td><a href="Amend.jsp">出庫</a></td>
  </tr>
  <tr>
  <td><a href="Select.jsp">查詢</a></td>
<%@ page language="java" contentType="text/html; charset=UTF-8"
      pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登錄界面</title>
</head>
<body>
<table width = "400" border ="0" height = "300" align = "center" cellpading ="0" style = "font-size:12px;color:#FFFFF;front-weight:bold">
<Tr height = "50" ><td>&nbsp;</td></Tr>
<tr>
   <td height = "200"><table width = "98%" border ="0" align = "center" cellpading = "0">
   <form >
  <tr>
   <td>歡迎使用本系統</td>
  </tr>
  <tr>
<%@ page language="java" contentType="text/html; charset=UTF-8"
      pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登錄界面</title>
</head>
<body>
<table width = "400" border ="0" height = "300" align = "center" cellpading ="0" style = "font-size:12px;color:#FFFFF;front-weight:bold">
<Tr height = "50" ><td>&nbsp;</td></Tr>
<tr>
   <td height = "200"><table width = "98%" border ="0" align = "center" cellpading = "0">
   <form name = "form1"  action = "chuli1.jsp" method = "post">
<tr>
<td>請輸入時間:</td><td><input type="text" name="time1" /></td>
</tr>
<tr>
<td><input name = "login" type = "submit" id = "login" value = "提交" class = "button"></td>
</tr>
 </form>
 </table>
 </td>
 </tr>
</table>
</html>

   <td>請選擇功能:</td>
  </tr>
    <tr>
   <td><a href="Selectware.jsp">商品名稱查詢</a></td>
  </tr>
    <tr>
   <td><a href="Selectdate.jsp">出入庫日期查詢</a></td>
  </tr>
 </form>
 </table>
 </td>
 </tr>
</table>
</body>
</html>

<%@ page language="java" contentType="text/html; charset=UTF-8"
      pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登錄界面</title>
</head>
<body>
<table width = "400" border ="0" height = "300" align = "center" cellpading ="0" style = "font-size:12px;color:#FFFFF;front-weight:bold">
<Tr height = "50" ><td> </td></Tr>
<tr>
   <td height = "200"><table width = "98%" border ="0" align = "center" cellpading = "0">
   <form name = "form1"  action = "addWareServlet" method = "post">
<tr>
<td>商品名稱:</td><td><input type="text" name="addname" /></td>
</tr>
<tr>
<td>生產廠家:</td><td><input type="text" name="addfactory" /></td>
</tr>
<tr>
<td>型號:</td><td><input type="text" name="addmodel" /></td>
</tr>
<tr>
<td>規格:</td><td><input type="text" name="addstandard" /></td>
</tr>
<tr>
<td><input name = "login" type = "submit" id = "login" value = "提交" class = "button"></td>
</tr>
 </form>
 </table>
 </td>
 </tr>
</table>
</html>

  (2)Dbutil文件

package com.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DBUtil {
    public static String db_url = "jdbc:mysql://localhost:3306/cangku001?characterEncoding=utf8&useSSL=true" ;
    public static String db_user = "root";
    public static String db_password = "wxy2724921017";

    public static Connection getConn() {
        Connection conn = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection(db_url, db_user, db_password);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return conn;
    }
    
    public static void close(Statement state, Connection conn) {
        if(state!=null) {
            try {
                state.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if(conn!=null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
    
    public static void close(ResultSet rs, Statement state, Connection conn) {
        if(rs!=null) {
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if(state!=null) {
            try {
                state.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if(conn!=null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}

(3)bean文件

package com.bean;

import java.util.Date;

public class FlowBean {
    private String name;
    private String factory;
    private String model;
    private String standard;
    private int number;
    private String danwei;
    private String person;
    private Date date;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getFactory() {
        return factory;
    }
    public void setFactory(String factory) {
        this.factory = factory;
    }
    public String getModel() {
        return model;
    }
    public void setModel(String model) {
        this.model = model;
    }
    public String getStandard() {
        return standard;
    }
    public void setStandard(String standard) {
        this.standard = standard;
    }
    public int getNumber() {
        return number;
    }
    public void setNumber(int number) {
        this.number = number;
    }
    public String getDanwei() {
        return danwei;
    }
    public void setDanwei(String danwei) {
        this.danwei = danwei;
    }
    public String getPerson() {
        return person;
    }
    public void setPerson(String person) {
        this.person = person;
    }
    public Date getDate() {
        return date;
    }
    public void setDate(Date date) {
        this.date = date;
    }


}
package com.bean;

public class WarehouseBean {
    private String name;
    private String factory;
    private String model;
    private String standard;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getFactory() {
        return factory;
    }
    public void setFactory(String factory) {
        this.factory = factory;
    }
    public String getModel() {
        return model;
    }
    public void setModel(String model) {
        this.model = model;
    }
    public String getStandard() {
        return standard;
    }
    public void setStandard(String standard) {
        this.standard = standard;
    }
    

}

(4)dao文件

package com.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.bean.FlowBean;
import com.bean.WarehouseBean;
import com.util.DBUtil;

public class FlowDao {
    public static int addFlow(String name,String factory,String model,String standard,int number,Timestamp date,String danwei,String person) throws Exception//增加
    {
        int count = 0;
        Connection conn = DBUtil.getConn();
        try {
            String sql="insert into flow values(?,?,?,?,?,?,?,?)";
            PreparedStatement preparedStatement=conn.prepareStatement(sql);
            preparedStatement.setString(1, name);
            preparedStatement.setString(2, factory);
            preparedStatement.setString(3, model);
            preparedStatement.setString(4, standard);
            preparedStatement.setInt(5, number);
            preparedStatement.setTimestamp(6, date);
            preparedStatement.setString(7, danwei);
            preparedStatement.setString(8, person);
            count=preparedStatement.executeUpdate();
            conn.close();
        }catch (Exception e) {
            e.printStackTrace();
        }
        return count;
    }
    public static List<FlowBean> select() {//查找
        List<FlowBean> beans = new ArrayList<FlowBean>();
        Connection conn = DBUtil.getConn();
        FlowBean adminBean=null;
        try {
            String sql="select * from Flow";
            Statement state = conn.createStatement();
            ResultSet rs = state.executeQuery(sql);
            while(rs.next()) {
                adminBean = new FlowBean();
                adminBean.setName(rs.getString("name"));
                adminBean.setFactory(rs.getString("factory"));
                adminBean.setModel(rs.getString("model"));
                adminBean.setStandard(rs.getString("standard"));
                adminBean.setNumber(rs.getInt("number"));
                adminBean.setDate(rs.getTimestamp("date"));
                adminBean.setDanwei(rs.getString("danwei"));
                adminBean.setPerson(rs.getString("person"));
                beans.add(adminBean);
            }
            conn.close();
        }catch (Exception e) {
            e.printStackTrace();
        }
        return beans;
        /*List
        
        return results;*/
    }

}

package com.dao;
import com.util.DBUtil;

import com.bean.WarehouseBean;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class WarehouseDao {
	public static int addWarehouse(String name,String factory,String model,String standard) throws Exception//增加
	{
		int count = 0;
		Connection conn = DBUtil.getConn();
		try {
			String sql="insert into Warehouse values(?,?,?,?)";
			PreparedStatement preparedStatement=conn.prepareStatement(sql);
			preparedStatement.setString(1, name);
			preparedStatement.setString(2, factory);
			preparedStatement.setString(3, model);
			preparedStatement.setString(4, standard);
			count=preparedStatement.executeUpdate();
			conn.close();
		}catch (Exception e) {
			e.printStackTrace();
		}
		return count;
	}
	public int DeleteWare(String name) throws Exception//刪除
	{
		int count=0;
		Connection conn = DBUtil.getConn();
		try {
			String sql="delete from Warehouse where name=?";
			PreparedStatement preparedStatement=conn.prepareStatement(sql);
			preparedStatement.setString(1, name);
			count=preparedStatement.executeUpdate();
			System.out.println(count);
			conn.close();
		}catch (Exception e) {
			e.printStackTrace();
		}
		return count;
	}
	public static List<WarehouseBean> select(String name) {//查找
		List<WarehouseBean> beans = new ArrayList<WarehouseBean>();
		Connection conn = DBUtil.getConn();
		WarehouseBean adminBean=null;
		try {
			String sql="select * from Warehouse";
			Statement state = conn.createStatement();
			ResultSet rs = state.executeQuery(sql);
			while(rs.next()) {
				adminBean = new WarehouseBean();
				adminBean.setName(rs.getString("name"));
				adminBean.setFactory(rs.getString("factory"));
				adminBean.setModel(rs.getString("model"));
				adminBean.setStandard(rs.getString("standard"));
				beans.add(adminBean);
			}
			
		
			conn.close();
		}catch (Exception e) {
			e.printStackTrace();
		}
		List<WarehouseBean> results = new ArrayList<WarehouseBean>();
		if(name!="")
		{
			Pattern pattern = Pattern.compile(name);
			for(int i=0;i<beans.size();i++)
			{
				Matcher matcher = pattern.matcher(((WarehouseBean)beans.get(i)).getName());
				if(matcher.find()){
				     results.add(beans.get(i));
				   }
			}
		}
		return results;
	}
	public static int testUpdate1(String xiugainame,String xiuname) throws Exception//修改
	{
		int count=0;
		Connection conn = DBUtil.getConn();
		try {
			String sql="update Warehouse set name=? where name=?";
			PreparedStatement preparedStatement=conn.prepareStatement(sql);
			preparedStatement.setString(1, xiuname);
			preparedStatement.setString(2, xiugainame);
			count=preparedStatement.executeUpdate();
			System.out.println(count);
			conn.close();
		}catch (Exception e) {
			e.printStackTrace();
		}
		return count;
	}
	public static int testUpdate2(String xiugainame,String xiufactory) throws Exception//修改
	{
		int count=0;
		Connection conn = DBUtil.getConn();
		try {
			String sql="update Warehouse set factory=? where name=?";
			PreparedStatement preparedStatement=conn.prepareStatement(sql);
			preparedStatement.setString(1, xiufactory);
			preparedStatement.setString(2, xiugainame);
			count=preparedStatement.executeUpdate();
			System.out.println(count);
			conn.close();
		}catch (Exception e) {
			e.printStackTrace();
		}
		return count;
	}
	public static int testUpdate3(String xiugainame,String xiumodel) throws Exception//修改
	{
		int count=0;
		Connection conn = DBUtil.getConn();
		try {
			String sql="update Warehouse set model=? where name=?";
			PreparedStatement preparedStatement=conn.prepareStatement(sql);
			preparedStatement.setString(1, xiumodel);
			preparedStatement.setString(2, xiugainame);
			count=preparedStatement.executeUpdate();
			System.out.println(count);
			conn.close();
		}catch (Exception e) {
			e.printStackTrace();
		}
		return count;
	}
	public static int testUpdate4(String xiugainame,String xiustandard) throws Exception//修改
	{
		int count=0;
		Connection conn = DBUtil.getConn();
		try {
			String sql="update Warehouse set standard=? where name=?";
			PreparedStatement preparedStatement=conn.prepareStatement(sql);
			preparedStatement.setString(1, xiustandard);
			preparedStatement.setString(2, xiugainame);
			count=preparedStatement.executeUpdate();
			System.out.println(count);
			conn.close();
		}catch (Exception e) {
			e.printStackTrace();
		}
		return count;
	}

}

  (5)servlet文件

package com.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.JOptionPane;
import java.sql.Timestamp;
import java.util.Date;
import com.bean.WarehouseBean;
import com.dao.WarehouseDao;
import com.util.DBUtil;
import com.dao.FlowDao;
@WebServlet("/addServlet")
public class addServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		String name=request.getParameter("addname");
		String factory=request.getParameter("addfactory");
		String model=request.getParameter("addmodel");
		String standard=request.getParameter("addstandard");
		String number=request.getParameter("addnumber");
		String danwei=request.getParameter("adddanwei");
		String person=request.getParameter("addperson");
		Date date = new Date();
		Timestamp timeStamp = new Timestamp(date.getTime());
		int num = Integer.parseInt(number);
		int a=0,b=0;
		FlowDao flow=new FlowDao();
		WarehouseDao ware=new WarehouseDao();
		try {
			a=flow.addFlow(name, factory, model, standard, num, timeStamp, danwei, person);
			b=ware.addWarehouse(name, factory, model, standard);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(a!=0&&b!=0)
	    {
	    	 int res=JOptionPane.showConfirmDialog(null, "操作成功", "是否繼續", JOptionPane.YES_NO_OPTION);
	    	                 if(res==JOptionPane.YES_OPTION){ 
	    	                	 request.getRequestDispatcher("jiemian.jsp").forward(request, response);   //點擊“是”後執行這個代碼塊
	    	                }else{
	    	                      System.out.println("選擇否後執行的代碼");    //點擊“否”後執行這個代碼塊
	    	                      return;
	    	                  } 
	    }
	    else
	    {
	    	JOptionPane.showMessageDialog(null, "操作錯誤", "請重新操作", JOptionPane.ERROR_MESSAGE);
	    	request.getRequestDispatcher("add.jsp").forward(request, response);
	    }
		

	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}

  

package com.servlet;

import java.io.IOException;
import java.sql.Timestamp;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.JOptionPane;

import com.bean.WarehouseBean;
import com.dao.WarehouseDao;
import com.util.DBUtil;
@WebServlet("/addWareServlet")
public class addWareServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public addWareServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String name=request.getParameter("addname");
        String factory=request.getParameter("addfactory");
        String model=request.getParameter("addmodel");
        String standard=request.getParameter("addstandard");
        Date date = new Date();
        Timestamp timeStamp = new Timestamp(date.getTime());
        int n=0;
        WarehouseDao ware=new WarehouseDao();
        try {
            n=ware.addWarehouse(name, factory, model, standard);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if(n!=0)
        {
             int res=JOptionPane.showConfirmDialog(null, "操作成功", "是否繼續", JOptionPane.YES_NO_OPTION);
                             if(res==JOptionPane.YES_OPTION){ 
                                 request.getRequestDispatcher("jiemian.jsp").forward(request, response);   //點擊“是”後執行這個代碼塊
                            }else{
                                  System.out.println("選擇否後執行的代碼");    //點擊“否”後執行這個代碼塊
                                  return;
                              } 
        }
        else
        {
            JOptionPane.showMessageDialog(null, "操作錯誤", "請重新操作", JOptionPane.ERROR_MESSAGE);
            request.getRequestDispatcher("addWare.jsp").forward(request, response);
        }

    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}

package com.servlet;

import java.io.IOException;
import java.sql.Timestamp;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.JOptionPane;

import com.dao.FlowDao;
import com.dao.WarehouseDao;


@WebServlet("/AmendServlet")
public class AmendServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		String name=request.getParameter("Amendname");
		String factory=request.getParameter("Amendfactory");
		String model=request.getParameter("Amendmodel");
		String standard=request.getParameter("Amendstandard");
		String number=request.getParameter("Amendnumber");
		String danwei=request.getParameter("Amenddanwei");
		String person=request.getParameter("Amendperson");
		Date date = new Date();
		Timestamp timeStamp = new Timestamp(date.getTime());
		int num = Integer.parseInt(number);
		int a=0,b=0;
		FlowDao flow=new FlowDao();
		WarehouseDao ware=new WarehouseDao();
		try {
			a=flow.addFlow(name, factory, model, standard, num, timeStamp, danwei, person);
			b=ware.DeleteWare(name);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(a!=0&&b!=0)
	    {
	    	 int res=JOptionPane.showConfirmDialog(null, "操作成功", "是否繼續", JOptionPane.YES_NO_OPTION);
	    	                 if(res==JOptionPane.YES_OPTION){ 
	    	                	 request.getRequestDispatcher("jiemian.jsp").forward(request, response);   //點擊“是”後執行這個代碼塊
	    	                }else{
	    	                      System.out.println("選擇否後執行的代碼");    //點擊“否”後執行這個代碼塊
	    	                      return;
	    	                  } 
	    }
	    else
	    {
	    	JOptionPane.showMessageDialog(null, "操作錯誤", "請重新操作", JOptionPane.ERROR_MESSAGE);
	    	request.getRequestDispatcher("Amend.jsp").forward(request, response);
	    }
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}

  

package com.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.JOptionPane;

import com.dao.WarehouseDao;
/**
 * Servlet implementation class AmendWareServlet
 */
@WebServlet("/AmendWareServlet")
public class AmendWareServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		String Amendname=request.getParameter("Amendname");
		String amendname=request.getParameter("amendname");
		String amendfactory=request.getParameter("amendfactory");
		String amendmodel=request.getParameter("amendmodel");
		String amendstandard=request.getParameter("amendstandard");
		WarehouseDao admin1=new WarehouseDao();
		int a1=0,a2=0,a3=0,a4=0;
	    try {
	    a1=admin1.testUpdate1(Amendname,amendname);
	    a2=admin1.testUpdate2(Amendname,amendfactory);
	    a3=admin1.testUpdate3(Amendname,amendmodel);
	    a4=admin1.testUpdate4(Amendname,amendstandard);
	    }catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	    if(a1!=0&&a2!=0&&a3!=0&&a4!=0)
	    {
	    	int res=JOptionPane.showConfirmDialog(null, "操作成功", "是否繼續", JOptionPane.YES_NO_OPTION);
            if(res==JOptionPane.YES_OPTION){ 
           	 request.getRequestDispatcher("jiemian.jsp").forward(request, response);   //點擊“是”後執行這個代碼塊
           }else{
                 System.out.println("選擇否後執行的代碼");    //點擊“否”後執行這個代碼塊
                 return;
             } 
	    }
	    else
	    {
	    	JOptionPane.showMessageDialog(null, "操作錯誤", "請重新操作", JOptionPane.ERROR_MESSAGE);
	    	request.getRequestDispatcher("AmendWare.jsp").forward(request, response);
	    }
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}

  

package com.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.JOptionPane;

import com.bean.WarehouseBean;
import com.dao.WarehouseDao;
import com.util.DBUtil;

@WebServlet("/DeleteWareServlet")
public class DeleteWareServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		String name=request.getParameter("Deletename");
		int n=0;
		WarehouseDao ware=new WarehouseDao();
		try {
			n=ware.DeleteWare(name);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(n!=0)
	    {
	    	 int res=JOptionPane.showConfirmDialog(null, "操作成功", "是否繼續", JOptionPane.YES_NO_OPTION);
	    	                 if(res==JOptionPane.YES_OPTION){ 
	    	                	 request.getRequestDispatcher("jiemian.jsp").forward(request, response);   //點擊“是”後執行這個代碼塊
	    	                }else{
	    	                      System.out.println("選擇否後執行的代碼");    //點擊“否”後執行這個代碼塊
	    	                      return;
	    	                  } 
	    }
	    else
	    {
	    	JOptionPane.showMessageDialog(null, "操作錯誤", "請重新操作", JOptionPane.ERROR_MESSAGE);
	    	request.getRequestDispatcher("DeleteWare.jsp").forward(request, response);
	    }
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}

三、實驗截圖

主界面

技術分享圖片

商品增加頁面

技術分享圖片

技術分享圖片

商品刪除

技術分享圖片

技術分享圖片

商品修改

技術分享圖片

技術分享圖片

入庫

技術分享圖片

技術分享圖片

出庫

技術分享圖片

技術分享圖片

查詢

技術分享圖片

錯誤提示

技術分享圖片

四、遇到的問題

今天連接數據庫時總是提示client dose not support authentication protocol requested by server;consider upgrading mysql client

後來通過cmd黑框修改了密碼的格式SET PASSWORD FOR -> ‘root‘@‘localhost‘ = OLD_PASSWORD(‘11111‘);問題得到解決;

連接數據庫時出現No suitable driver found for jdbc:sql://localhost:3307/choose?useSSL=false錯誤。後來通過查詢在數據庫後面加上了

?characterEncoding=utf8&useSSL=true一行代碼解決了此問題。

庫存物資管理系統