• 库存管理系统


    还有 

        

    首先建立一个包 建立Test类和util类

    import  Ke.util;
    import java.text.DateFormat;
    import java.text.ParsePosition;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.sql.*;
    import java.util.Scanner;
    public class Test {
        static Connection conn;
        static PreparedStatement ps = null;
        static ResultSet rs;
        static String sql = "select * from Ku_c";
        static util ut= new util();
        static Scanner in = new Scanner(System.in);
         static int id;
         static String name;//商品名称
         static String name_C;//生产厂家
         static String Xing_hao;//型号
         static String Gui;//规格
         static int num;//数量
         static Date create_date=new Date();
         static String date;
         static String name_Dan;//入库/出库单位
         static String name_peo;//送货提货人
         public static int a_id() {
             return id;
         }
         public static String a_name() {
             return name;
         }
         public static String a_name_C() {
             return name_C;
         }
         public static String a_Xing_hao() {
             return Xing_hao;
         }
         public static String a_Gui() {
             return Gui;
         }
         public static int a_num() {
             return num;
         }
        
         public static Date a_create_date() {
                return create_date;
         }
         public static String a_date() {
             return date;
         } 
         public static String a_name_Dan() {
             return name_Dan;
         } 
         public static String a_name_peo() {
             return name_peo;
         }
    public static int add(String Name,int Id,String Name_C,String Xing,String gui,int Num,String Name_Dan,String Name_peo,String Date)
    {
         conn= ut.getConn();
         String sql="insert into Ku_c values(?,?,?,?,?,?,?,?,?,?)";
         int b=0;
         try {
             ps=conn.prepareStatement(sql);
             ps.setString(2,Name);
             ps.setInt(1,Id);
             ps.setString(3, Name_C);
             ps.setString(4, Xing);
             ps.setString(5, gui);
             ps.setInt(6, Num);
             ps.setString(8, Name_Dan);
             ps.setString(9, Name_peo);
             create_date=new Date();
             Timestamp t=new Timestamp(create_date.getTime());
             System.out.println(t);
             ps.setTimestamp(7, t);
             ps.setString(10, Date);
             
             /*DateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
             String i=df.format(create);
             ps.setString(5, i);*/
             
             //ps.setString(5, i);
             
             int a=ps.executeUpdate();
             if(a>0) {
                 b++;
                 System.out.println("添加成功");
                 
             }
             else {
                 System.out.println("添加失败");
             }
         }catch(Exception e) {
             e.printStackTrace();
         }
         try {
             if(ps!=null)ps.close();
             if(conn!=null)conn.close();
         }catch(Exception e2) {
             e2.printStackTrace();
         }
        return b;
    }
    public static int uqdate(String Name,int Id,String Name_C,String Xing,String gui,int Num,String Name_Dan,String Name_peo,String Date)
    {
    
        int b=0;
        conn=ut.getConn();
        ps=null;
        sql="update Ku_c set id=?,name_C=?,Xing_hao=?,Gui=?,num=?,name_Dan=?,name_peo=?,date=? where name=?";
        try {
             ps=conn.prepareStatement(sql);
             ps.setInt(1,Id);
             ps.setString(2,Name_C);
             ps.setString(3,Xing);
             ps.setString(4,gui);
             ps.setInt(5,Num);
             ps.setString(6,Name_Dan);        
             ps.setString(7,Name_peo);
             ps.setString(8,Date );
             ps.setString(9,Name );
             
             int a=ps.executeUpdate();
             if(a>0) {
                 b++;
                 System.out.println("修改成功");
                 
             }
             else {
                 System.out.println("修改失败");
             }
        }catch(Exception e) {
            e.printStackTrace();
        }
        try {
             if(ps!=null)ps.close();
             if(conn!=null)conn.close();
         }catch(Exception e2) {
             e2.printStackTrace();
         }
        return b;
        
    }
    public static int delete(String A) {
        int b=0;
        conn=ut.getConn();
        ps=null;
        sql="delete from Ku_c where name=?";
        
        try {
            ps=conn.prepareStatement(sql);
            ps.setString(1,A );
            int a=ps.executeUpdate();
             if(a>0) {
                 b++;
                 System.out.println("删除成功");
                 
             }
             else {
                 System.out.println("删除失败");
             }
        }catch(Exception e) {
            e.printStackTrace();
        }
        try {
             if(ps!=null)ps.close();
             if(conn!=null)conn.close();
         }catch(Exception e2) {
             e2.printStackTrace();
         }
        return b;
        
    }
    public static void find_name(String a) {
        conn=ut.getConn();
        ps=null;
        ResultSet rs=null;
        sql="select * from Ku_c where name=?";
        try {
            ps=conn.prepareStatement(sql);
            ps.setString(1, a);
            rs=ps.executeQuery();
            if(rs.next()) {
                 id = rs.getInt("id");
                 name = rs.getString("name");
                 name_C = rs.getString("name_C");
                 Xing_hao = rs.getString("Xing_hao");
                 Gui = rs.getString("Gui");
                 num = rs.getInt("num");
                 create_date=rs.getDate("create_date");
                 name_Dan = rs.getString("name_Dan");
                 name_peo = rs.getString("name_peo");
                 date = rs.getString("date");
                 
                 System.out.println(name+id+name_C+Xing_hao+Gui+num+create_date+name_Dan+name_peo+date);
            }
        }catch(SQLException e) {
            e.printStackTrace();
        }finally {
            try {
                 if(ps!=null)ps.close();
                 if(conn!=null)conn.close();
             }catch(Exception e2) {
                 e2.printStackTrace();
             }
        }
    }
    public static void find_date(String a) {
        conn=ut.getConn();
        ps=null;
        ResultSet rs=null;
        sql="select * from Ku_c where date=?";
        try {
            ps=conn.prepareStatement(sql);
            ps.setString(1, a);
            rs=ps.executeQuery();
            if(rs.next()) {
                 id = rs.getInt("id");
                 name = rs.getString("name");
                 name_C = rs.getString("name_C");
                 Xing_hao = rs.getString("Xing_hao");
                 Gui = rs.getString("Gui");
                 num = rs.getInt("num");
                 create_date=rs.getDate("create_date");
                 name_Dan = rs.getString("name_Dan");
                 name_peo = rs.getString("name_peo");
                 System.out.println(name+id+name_C+Xing_hao+Gui+num+create_date+name_Dan+name_peo+date);
            }
        }catch(SQLException e) {
            e.printStackTrace();
        }finally {
            try {
                 if(ps!=null)ps.close();
                 if(conn!=null)conn.close();
             }catch(Exception e2) {
                 e2.printStackTrace();
             }
        }
    }
    public static void main(String[] args) {
    
        //System.out.println("请输入要删除商品");
        System.out.println("请输入查找商品:");
        Scanner scan=new Scanner(System.in);
        String a=scan.next();
        delete(a);
        //find_name(a);
        //find_date(a);
    }
    }



     然后建立zhu.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=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    <a href = "add.jsp">入库</a></br>
    <a href = "find.jsp">商品查询 </a></br>
    <a href = "find_date.jsp">时间查询</a></br>
    <a href = "delete.jsp">出库</a></br>
    <a href = "update.jsp">商品修改</a></br>
    
    </body>
    </html>
    

      建立add.jsp

    <%@page import="Ke.Test"%>
    <%@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>
     <form action="addresult.jsp" method="post" id="form"  >
    
     <input type="hidden" name="methodName" value="0"/>
    
    <h4> 商品名称 :<input type="text" name="name"title="不能为空"></input><br></h4>
    <h4> 成产厂商 :<input type="text" name="name_C"title="不能为空"></input><br></h4>
    <h4> 商品型号(数字) :<input type="text" name="id"title="不能为空"></input><br></h4>
    <h4> 商品规格 :<input type="text" name="Gui"title="不能为空"></input><br></h4>
    <h4> 商品等级 :<input type="text" name="Xing_hao"title="不能为空"></input><br></h4>
    <h4> 商品数量(数字) :<input type="text" name="num"title="不能为空"></input><br></h4>
    <h4> 送货(取货)单位 :<input type="text" name="name_Dan"title="不能为空"></input><br></h4>
    <h4> 送货(取货)人姓名:<input type="text" name="name_peo"title="不能为空"></input><br></h4>
    <h4> 日期 :<input type="text" name="Date"title="不能为空"></input><br></h4>
     <input type="submit" value="完成"/>
       </form>
     
    </body>
    </html>
    

      建立addresult.jsp类

    <%@page import="Ke.Test"%>
    <%@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>
    <%
    request.setCharacterEncoding("utf-8");
    String a=request.getParameter("id");
    String b=request.getParameter("num");
    int a_i=Integer.parseInt(a);
    int a_s=Integer.parseInt(b);
     if(Test.add(request.getParameter("name"),a_i,request.getParameter("name_C"),request.getParameter("Xing_hao"),request.getParameter("Gui"),a_s,request.getParameter("name_Dan"),request.getParameter("name_peo"),request.getParameter("Date"))==1)
     {
    	 {
    			out.print("<script language = 'javascript'>alert('添加成功');</script>");
    			response.setHeader("refresh", "0;url=Zhu.jsp");
    		    }
     }
     else{
    	 out.print("<script language = 'javascript'>alert('添加失败');</script>");
    	 response.setHeader("refresh", "0;url=Zhu.jsp");
    		//out.println("添加失败");
     }
     %>
    </body>
    </html>
    

      建立find.jsp类

    <%@page import="Ke.Test"%>
    <%@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=ISO-8859-1">
    <title>商品名称 查找界面</title>
    
    </head>
    <body>
     <form action="findresult.jsp" method="post" id="form"  >
    
     <input type="hidden" name="methodName" value="0"/>
    
    <h4>  商品名称:<input type="text" name="name"title="课程不能为空"></input><br></h4>
     <input type="submit" value="完成"/>
       </form>
     
    </body>
    </html>
    

      建立findresult.jsp类

    <%@page import="Ke.Test"%>
    <%@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=ISO-8859-1">
    <title>查找结果</title>
    </head>
    <body>
    <%
    request.setCharacterEncoding("utf-8");
     Test.find_name(request.getParameter("name"));
    out.println(Test.a_id());
    out.println(Test.a_name());
    out.println(Test.a_name_C());
    out.println(Test.a_Xing_hao());
    out.println(Test.a_Gui());
    out.println(Test.a_num());
    out.println(Test.a_create_date());
    out.println(Test.a_date());
    out.println(Test.a_name_Dan());
    out.println(Test.a_name_peo());
    		
     %>
    </body>
    </html>
    

      建立update.jsp类

    <%@page import="Ke.Test"%>
    <%@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=ISO-8859-1">
    <title>修改界面</title>
    
    </head>
    <body>
     <form action="uqdateresult.jsp" method="post" id="form"  >
    
     <input type="hidden" name="methodName" value="0"/>
    
    <h4> 商品名称 :<input type="text" name="name"title="不能为空"></input><br></h4>
    <h4> 成产厂商 :<input type="text" name="name_C"title="不能为空"></input><br></h4>
    <h4> 商品型号(数字) :<input type="text" name="id"title="不能为空"></input><br></h4>
    <h4> 商品规格 :<input type="text" name="Gui"title="不能为空"></input><br></h4>
    <h4> 商品等级 :<input type="text" name="Xing_hao"title="不能为空"></input><br></h4>
    <h4> 商品数量(数字) :<input type="text" name="num"title="不能为空"></input><br></h4>
    <h4> 送货(取货)单位 :<input type="text" name="name_Dan"title="不能为空"></input><br></h4>
    <h4> 送货(取货)人姓名:<input type="text" name="name_peo"title="不能为空"></input><br></h4>
    <h4> 日期 :<input type="text" name="Date"title="不能为空"></input><br></h4>
     <input type="submit" value="完成"/>
       </form>
    </body>
    </html>
    

      建立updateresult.jsp类

    <%@page import="Ke.Test"%>
    <%@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=ISO-8859-1">
    <title>修改结果</title>
    </head>
    <body>
    <%
    request.setCharacterEncoding("utf-8");
    String a=request.getParameter("id");
    String b=request.getParameter("num");
    int a_i=Integer.parseInt(a);
    int a_s=Integer.parseInt(b);
     if(Test.uqdate(request.getParameter("name"),a_i,request.getParameter("name_C"),request.getParameter("Xing_hao"),request.getParameter("Gui"),a_s,request.getParameter("name_Dan"),request.getParameter("name_peo"),request.getParameter("Date"))==1)
     {
    	 {
    			out.print("<script language = 'javascript'>alert('修改成功');</script>");
    			response.setHeader("refresh", "0;url=Zhu.jsp");
    		    }
     }
     else{
    	 out.print("<script language = 'javascript'>alert('修改失败');</script>");
    	 response.setHeader("refresh", "0;url=Zhu.jsp");
    		//out.println("添加失败");
     }
     %>
    </body>
    </html>
    

      建立find_date.jsp类

    <%@page import="Ke.Test"%>
    <%@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=ISO-8859-1">
    <title>时间查询</title>
    </head>
    <body>
    <form action="findresult.jsp" method="post" id="form"  >
    
     <input type="hidden" name="methodName" value="0"/>
    
    <h4>  日期:<input type="text" name="date"title="课程不能为空"></input><br></h4>
     <input type="submit" value="完成"/>
       </form>
     
    </body>
    </html>
    

      建立find_date_result类

    <%@page import="Ke.Test"%>
    <%@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=ISO-8859-1">
    <title>时间查询结果</title>
    </head>
    <body>
    <%
    request.setCharacterEncoding("utf-8");
     Test.find_date(request.getParameter("date"));
    out.println(Test.a_id());
    out.println(Test.a_name());
    out.println(Test.a_name_C());
    out.println(Test.a_Xing_hao());
    out.println(Test.a_Gui());
    out.println(Test.a_num());
    out.println(Test.a_create_date());
    out.println(Test.a_date());
    out.println(Test.a_name_Dan());
    out.println(Test.a_name_peo());
    		
     %>
    </body>
    </html>
    

      建立delete.jsp类

    <%@page import="Ke.Test"%>
    <%@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=ISO-8859-1">
    <title>删除界面</title>
    </head>
    <body>
    <form action="deleteresult.jsp" method="post" id="form" onSubmit="return validate()" >
    
     <input type="hidden" name="methodName" value="0"/>
    
    <h4>  商品名称:<input type="text" name="name"title="课程不能为空"></input><br></h4>
    
    <input type="submit" value="完成"/>
       </form>
     
    </body>
    </html>
    

      建立deleteresult.类

    <%@page import="Ke.Test"%>
    <%@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>
    <%
    request.setCharacterEncoding("utf-8");
     if(Test.delete(request.getParameter("name"))==1)
     {
    	 {
    			out.print("<script language = 'javascript'>alert('删除成功');</script>");
    			response.setHeader("refresh", "0;url=Zhu.jsp");
    		    }
     }
     else{
    	 out.print("<script language = 'javascript'>alert('删除失败');</script>");
    	 response.setHeader("refresh", "0;url=Zhu.jsp");
    		//out.println("添加失败");
     }
     %>
    </body>
    </html>
    

      最后设置路径buildpath  configureBuildpath

     还有添加jdbc包

     
  • 相关阅读:
    Redis --- 客户端 --- Another Redis Desktop Manager
    Docker --- 记录安装与使用过程中遇到的问题
    Docker安装教程
    Python --- pip --- No module named 'pip'异常问题
    天气接口测试用例生成报告
    jsonpath使用
    python小知识,字典
    python小知识,列表推导式
    python小知识,sort和serted的区别
    如何查看app启动的activity
  • 原文地址:https://www.cnblogs.com/adret/p/10116946.html
Copyright © 2020-2023  润新知