Java Warehouse Management System (i)

Source: Internet
Author: User

From small to large do not write diary habit, but in the Internet open, sharing principle, and horse soldier teacher once said: When you learn some skills, see others are being troubled by what you will, you should go to help him. So the warehouse management system of detailed records. It may not be that professional, but it can be understood in a basic sense. I started programming, there are errors please point out. First, introduce the main idea of the system. 1.MVC frame: M (model) V (view) C (Controller) The framework separates a complex project into small pieces. Each part is related to each other and is responsible for its responsibilities. Model, which is the main part of a program, consists primarily of business data and business logic. View, the part of the program that is presented to the user, is the interface between user and program interaction. Controller, which is a part of the business model that is used to process user input data that has been updated. But this framework improves the complexity of a project and increases the complexity of the structure. But this project is not very difficult, and the complexity is not high. So I used the MVC design pattern, and in the project I used the general MVC subcontracting Structure: Bean Package--the bean structure that was responsible for the project object.                       JavaBean is actually a specification that facilitates encapsulation and reuse.                       dao--is responsible for database operations, and uses interface-oriented, the main method implementation encapsulated into an interface, method to inherit the interface to achieve the function. view--is responsible for the view and calling method util--is responsible for database Connection 2. Interface programming: interface-oriented programming the detailed implementation of the method is encapsulated into an interface, the method inherits the interface and then invokes the method, improving the readability of the program. We can only care about who the interface should be used by. Java can inherit multiple interfaces only by inheriting the parent class alone. In short, the benefits of interface-oriented programming may not be a small project to see, and a large project can see its value, you can learn it carefully.

Next we start from 0 to explain the implementation of this project, the project's functional analysis of the steps to automatically ignore ... Let's set up a database table for Goods,storage,users

Next we write a Db.java class that implements the database connection in util. This connection I use the properties file, implementation of the file read connection database four attributes, the implementation of the advantages of the method: Here I use a MySQL database, if one day we change a database of access, its drive will change, This is if we use the traditional connection method need to pause the program modification, even caused the program error.

Import Java.awt.im.InputContext;
Import java.io.IOException;
Import Java.io.InputStream;
Import java.sql.Connection;
Import Java.sql.DriverManager;
Import java.util.Properties;

public class DB {

Static Properties Props=null;
static{

try {
Props=new Properties ();

InputStream In=db.class.getresourceasstream ("dbconfig.properties");
Props.load (in);
} catch (IOException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}
Database connection
public static Connection con;
Public DB () {
try {
Load Driver
Class.forName (Props.getproperty ("Driver"));
Get connections
Con=drivermanager.getconnection (props.getproperty ("url"), Props.getproperty ("username"), Props.getproperty (" Password "));
} catch (Exception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}
Get connections
public static Connection getconnection () {
if (con = = null) {
New DB ();
}
return con;
}
}

Dbconfig.properties File Contents

Driver=com.mysql.jdbc.driver
Username=root
Password=root
Url=jdbc:mysql://localhost:3306/test

This enables the database to be connected and works better.

Java Warehouse Management System (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.