Java Basics practicing Small Project __java

Source: Internet
Author: User
Tags create database in domain
Accounting Software 1. Project Introduction 1.1. Project Arrangements 1.1.1. Project Objectives

This project is the Java EE Foundation Class Comprehensive project, contains several knowledge points, achieves the basic class to learn the knowledge synthesis use, enhances our to the project understanding and the knowledge point application.

The methods that are familiar with the view layer, service layer, and DAO layer invoke each other operations,

Skilled dbutils Operation database table complete the increase and deletion check

Through this project, let us understand the company project development process, fully grasp the project requirements analysis, design and functional code implementation. Improve students ' ability to analyze requirements and function independently. 1.1.2. Project Time

This project is completed through a 1-day course. 1.2. Project Functional Analysis 1.2.1. Project Demo 1.2.2. Project Function Introduction

L Check the accounts

L Multi-Conditional combination inquiry Account

L Add Accounting

L Editorial Accounts

• Delete accounts

2. Project Environment Build 2.1. technology Selection and Jar package Introduction

Each project uses a number of technologies that are already mature, often provided by a professional organization or team for free open source technology. In the course of future learning, we will gradually understand these professional organizations. The techniques used in this project are as follows:

• Apache Commons components:

Øcommons-dbutils-1.4.jar: encapsulates and simplifies JDBC;

Øcommons-dbcp-1.4.jar:apache Commons provides the database connection pool component, named DBCP;

The ØCOMMONS.POOL-1.3.JAR:DBCP connection pool relies on the jar package;

L mysql-connector-java-5.1.28-bin.jar:mysql JDBC Driver package, the MySQL database connection with JDBC must use this jar package. 2.2. Introduction to Tools Class

Each project will use a number of tool classes, this project is no exception. We are not going to teach you how to implement these classes, but rather to let you know how we use these tools in our project, and the following are the tools and descriptions used in this project:

L Jdbcutils: Used to create database connection pool objects;

In the implementation of the project, we will explain the use of the tool class, here is not too much introduction.

Jdbcutils.java

Public class jdbcutils {

Public static Final Stringdriver_class_name = "Com.mysql.jdbc.Driver";

Public static Final StringURL = "JDBC:MYSQL://LOCALHOST:3306/GJP";

Public static Final StringUSERNAME = "root";

Public static Final StringPASSWORD = "root";

private static Basicdatasourcedatasource = new basicdatasource ();

Static {

Datasource.setdriverclassname (driver_class_name);

Datasource.seturl (URL);

Datasource.setusername (USERNAME);

Datasource.setpassword (PASSWORD);

}

Public Static DataSource Getdatasource () {

return dataSource;

}

}

2.3. data table creation

Table design is important for a project because all operations in the application are based on database tables, so the first step is to create a database table.

The Housekeeper Project database design is very simple, we only need to find the Gjp.sql file, and then execute it. The following is an SQL statement that creates a library and a table: 2.3.1. Creating a database

Create housekeeper Database Gjp

CREATE DATABASE GJP;

2.3.2. Create a database table

Create Account Table Gjp_zhangwu

CREATE TABLE Gjp_zhangwu (

Zwid INT PRIMARY KEY auto_increment,

Flname VARCHAR(200),

Money DOUBLE,

Zhanghu VARCHAR(100),

Createtime DATE,

Description VARCHAR(1000)

);

2.3.3. Adding table Data

Add Account table Data

INSERT into Gjp_zhangwu (zwid,flname,money,zhanghu,createtime,description)VALUES (1, ' eating expenses ', 247, ' Bank of Communications ', ' 2016-03-02 ', ' family dinner ';

INSERT into Gjp_zhangwu (zwid,flname,money,zhanghu,createtime,description)VALUES (2, ' wage income ', 12345 , ' cash ', ' 2016-03-15 ', ' open salary ');

INSERT into Gjp_zhangwu (zwid,flname,money,zhanghu,createtime,description)VALUES (3, ' costume expenses ', 1998, ' Cash ', ' 2016-04-02 ', ' buy clothes ');

INSERT into Gjp_zhangwu (zwid,flname,money,zhanghu,createtime,description)VALUES (4, ' eating expenses ', 325, ' Cash ', ' 2016-06-18 ', ' Friends dinner ');

INSERT into Gjp_zhangwu (zwid,flname,money,zhanghu,createtime,description)VALUES (5, ' stock income ', 8000, ' ICBC ', ' 2016-10-28 ', ' stock rally ');

INSERT into Gjp_zhangwu (zwid,flname,money,zhanghu,createtime,description)VALUES (6, ' stock income ', 5000, ' ICBC ', ' 2016-10-28 ', ' Stocks rose ' again;

INSERT into Gjp_zhangwu (zwid,flname,money,zhanghu,createtime,description)VALUES (7, ' wage income ', 5000, ' Bank of Communications ', ' 2016-10-28 ', ' pay again ';

INSERT into Gjp_zhangwu (zwid,flname,money,zhanghu,createtime,description)VALUES (8, ' gift Expense ', 5000, ' Cash ', ' 2016-10-28 ', ' friend marriage ';

INSERT into Gjp_zhangwu (zwid,flname,money,zhanghu,createtime,description)VALUES (9, ' Other expenses ', 1560, ' Cash ', ' 2016-10-29 ', ' lost money ');

INSERT into Gjp_zhangwu (zwid,flname,money,zhanghu,createtime,description)VALUES (10, ' traffic expenses ', 2300 , ' Bank of Communications ', ' 2016-10-29 ', ' oil is still rising ');

INSERT into Gjp_zhangwu (zwid,flname,money,zhanghu,createtime,description)VALUES (11, ' meal expense ', 1000 , ' ICBC ', ' 2016-10-29 ', ' eat again ');

INSERT into Gjp_zhangwu (zwid,flname,money,zhanghu,createtime,description)VALUES (12, ' wage income ', 1000 , ' cash ', ' 2016-10-30 ', ' open capital ');

INSERT into Gjp_zhangwu (zwid,flname,money,zhanghu,createtime,description)VALUES (13, ' Traffic expenses ', 2000 , ' cash ', ' 2016-10-30 ', ' The ticket is very expensive ');

INSERT into Gjp_zhangwu (zwid,flname,money,zhanghu,createtime,description)VALUES (14, ' wage income ', 5000 , ' cash ', ' 2016-10-30 ', ' open capital ' again;

2.4. The role of Project layering (subcontracting)

Why should the program subcontract tiering?

Take the customer to the restaurant to eat case analysis:

Hotel: A waiter to fix (reception customers \ La carte/stir fry)

Grand Hotel:

L Welcome Guests (whether there is a reservation asked to eat Chinese food or Western food or barbecue, etc. \ Several dining lead to the designated rooms \ Find a la carte for customers to order)

L a la carte (record customer order content \ Record whether there are diet and other issues \ Find a chef to stir fry for customers)

L Cook (according to the list of customer dishes, cooking)

Through the case found that when the program is small, you can complete a person, but when the program is large, a person is difficult to complete, at this time, to use a number of people to cooperate in the way to complete the program development.

Multi-person collaboration will come across work assignment issues, when we think that everyone is responsible for completing a piece of the project. So, the division of this piece of content, we need to adopt a layered (subcontracting) way to complete.

The following figure (User registration function) to explain the common in the project hierarchy (subcontracting).

L View Layer function: Views layer, that is, the interface in the project

L Controller Layer function: Control layer, obtain data on interface, set data for interface, and deliver function to business layer processing

L Service Layer function: Business layer, function implementation, interacting with controller control layer and data Access layer DAO, handing the operation of database to DAO data access layer to handle

L DAO Layer function: Data access layer, used to manipulate data in database tables

L DB Database: This refers to MySQL

L Domain Entity package: storage JavaBean

L Tools Toolkit: Storage of tools used in projects

Test Package: Code 2.5 that stores the project's functional tests . Project creation and package management

1. Use Eclipse to create a Java project named GJP

2. Create the Project Package

Øcn.itcast.gjp.app: Store Main method class;

Øcn.itcast.gjp.domain: Storing JavaBean;

Øcn.itcast.gjp.view: Storage interface, and performance layer class;

Øcn.itcast.gjp.service: Store business layer class;

Øcn.itcast.gjp.dao: Store data access Layer class;

Øcn.itcast.gjp.tools: Storage Tool Class

3. Create Lib folder to store the jar package used

3. function Module 3.1. Related class creation

Complete the creation of classes in this project without adding code to the class.

1. Copy the prepared tool class Jdbcutils.java into the tools package;

2. Copy jar package Mysql-connector-java-5.1.28-bin.jar, Commons-dbutils-1.4.jar, Commons-dbcp-1.4.jar, Commons-pool-1.3.jar, to the Lib folder, through the build path operation, added to the Classpath path, provided to the jdbcutils use;

3. In the app package, create the class Mainapp.java, write main main method, to complete the start of this project

4. In domain package, create class Zhangwu.java, which is used to encapsulate the javabean of accounting information.

5. In the DAO package, create a class Zhangwudao.java to add a member variable Queryrunner object to the Zhangwudao class because we manipulate the database using Dbutils.

6. In the service package, create a class Zhangwuservice.java, add a member variable of type Zhangwudao to the Zhangwuservice class, because the service relies on DAO.

7. In the view package, create a class Mainview.java, add a member variable of type Zhangwuservice to the Mainview class, because view depends on the service in this project.

Write the Mainapp.java in the app package

/**

* Main Method class

*/

Public class Mainapp {

Public static void Main (String[]args) {

}

}

Write Zhangwu.java in Domain package

/**

* Accounting category

*/

Public class Zhangwu {

}

Write Zhangwudao.java in DAO package

/**

* Accounting Data Layer Class

*/

public class zhangwudao{

Get the database connection pool, get the object Queryrunner of manipulating table data

Queryrunner qr = new Queryrunner (Jdbcutils.getdatasource ());

}

Writing service packs, Zhangwuservice.java

/**

* Accounting Business Layer Class

*/

Public class Zhangwuservice {

Service is dependent on DAO

Private Zhangwudao Zhangwudao =new Zhangwudao ();

}

Write the view package, Mainview.java

public class  mainview {

//View dependent service

In this project Private  zhangwuservice

Related Article

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.