Using Java to Compile the Book Management System in Computer Graduation Project

1. Function

(1) User login
(2) Book category management
(3) Book management
(4) Logout

Two, tools

(1) JAVA programming: eclipes (1.8 soon version)
(2) SQL: mysql
(3) Jdbc: jar (mysql-connector-java-5.1.40-bin.jar)

Three, effect display

(1) Login

image

(2) Main interface

image

(3) Book category addition

image

(4) Book category management

image

(5) Book add

image

(6) Book management

image

(7) About the author

image

Four database design

image

(1)t_user表

image

(2)t_bookType表

image

(3) t_book table

image

(4) Java level analysis:

(1) Logic diagram

image

(2) Package structure

image

(5) Database level analysis:

1 ER analysis

image

2 data

User: User ID, User Name, Password
Book Category: Book Category Number, Book Category Name
Book: Book Number, Book Name, Book Author, Book Price, Book Description, Book Category (foreign key)

Book category and book are related to each other according to book category

3 Establishment of database table
(1) t_use user information table
(2) t_bookType book category management table
(3) t_book book information management table

4 database table association (foreign key association)

image

(6) Main Java code analysis:

(1) Dao class (take BookDao as an example)

package com.java1234.dao;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.java1234.model.Book;
import com.java1234.model.BookType;
import com.java1234.util.StringUtil;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;

/**
 * 图书Dao类
 * @author H_Pioneer
 *
 */
public class BookDao {
    
    
	
	/**
	 * 图书添加
	 * @param con
	 * @param book
	 * @return
	 * @throws Exception
	 */
	public int add(Connection con,Book book)throws Exception{
    
    
		String sql="insert into t_book values(null,?,?,?,?,?,?)";
		PreparedStatement pstmt=(PreparedStatement) con.prepareStatement(sql);
		pstmt.setString(1, book.getBookName());
		pstmt.setString(2, book.getAuthor());
		pstmt.setString(3, book.getSex());
		pstmt.setFloat(4, book.getPrice());
		pstmt.setInt(5, book.getBookTypeId());
		pstmt.setString(6, book.getBookDesc());
		return pstmt.executeUpdate();
	}
	
	/**
	 * 图书信息查询
	 * @param con
	 * @param book
	 * @return
	 * @throws Exception
	 */
	public ResultSet list(Connection con,Book book)throws Exception{
    
    
		StringBuffer sb=new StringBuffer("select * from t_book b,t_bookType bt where b.bookTypeId=bt.id");
		if(StringUtil.isNotEmpty(book.getBookName())){
    
    
			sb.append(" and b.bookName like '%"+book.getBookName()+"%'");
		}
		if(StringUtil.isNotEmpty(book.getAuthor())){
    
    
			sb.append(" and b.author like '%"+book.getAuthor()+"%'");
		}
		if(book.getBookTypeId()!=null && book.getBookTypeId()!=-1){
    
    
			sb.append(" and b.bookTypeId="+book.getBookTypeId());
		}
		PreparedStatement pstmt=(PreparedStatement) con.prepareStatement(sb.toString());
		return pstmt.executeQuery();
	}
	
	/**
	 * 图书信息删除
	 * @param con
	 * @param id
	 * @return
	 * @throws SQLException
	 */
	public int delete(Connection con,String id)throws Exception{
    
    
		String sql="delete from t_book where id=?";
		PreparedStatement pstmt=(PreparedStatement) con.prepareStatement(sql);
		pstmt.setString(1, id);
		return pstmt.executeUpdate();
	}
	
	/**
	 * 图书信息修改
	 * @param con
	 * @param book
	 * @return
	 * @throws Exception
	 */
	public int update(Connection con,Book book)throws Exception{
    
    
		String sql="update t_book set bookName=?,author=?,sex=?,price=?,bookDesc=?,bookTypeId=? where id=?";
		PreparedStatement pstmt=(PreparedStatement) con.prepareStatement(sql);
		
		
		pstmt.setString(1, book.getBookName());
		pstmt.setString(2, book.getAuthor());
		pstmt.setString(3, book.getSex());
		pstmt.setFloat(4, book.getPrice());
		pstmt.setString(5, book.getBookDesc());
		pstmt.setInt(6, book.getBookTypeId());
		pstmt.setInt(7, book.getId());
		return pstmt.executeUpdate();
	}
	
	/**
	 * 
	 * @param con
	 * @param bookTypeId
	 * @return
	 * @throws Exception
	 */
	public boolean existBookByBookTypeId(Connection con,String bookTypeId)throws Exception{
    
    
		String sql="select * from t_book where bookTypeId=?";
		PreparedStatement pstmt=(PreparedStatement) con.prepareStatement(sql);
		pstmt.setString(1, bookTypeId);
		ResultSet rs = pstmt.executeQuery();
		String string = new String();
		return rs.next();
	}
}

(2) Model class (take BookModel as an example)

package com.java1234.model;


/**
 * 图书实体类
 * @author H_Pioneer
 *
 */
public class Book {
    
    

	private int id; //编号
	private String bookName;  //图书名称
	private String author;  //作者
	private String sex;  //性别
	private float price;  //价格
	private Integer bookTypeId;  //图书类别
	private String bookTypeName;  //图书类别名称
	private String bookDesc;  //备注
	
	
	
	public Book(int id2, String bookName, String author, String sex, float price, Integer bookTypeId, String bookDesc) {
    
    
		super();
		this.id = id2;
		this.bookName = bookName;
		this.author = author;
		this.sex = sex;
		this.price = price;
		this.bookTypeId = bookTypeId;
		this.bookDesc = bookDesc;
	}

	public Book(String bookName, String author, Integer bookTypeId) {
    
    
		super();
		this.bookName = bookName;
		this.author = author;
		this.bookTypeId = bookTypeId;
	}

	public Book(String bookName, String author, String sex, float price, Integer bookTypeId, String bookDesc) {
    
    
		super();
		this.bookName = bookName;
		this.author = author;
		this.sex = sex;
		this.price = price;
		this.bookTypeId = bookTypeId;
		this.bookDesc = bookDesc;
	}
	
	public Book() {
    
    
		super();
		// TODO Auto-generated constructor stub
	}
	public int getId() {
    
    
		return id;
	}
	public void setId(int id) {
    
    
		this.id = id;
	}
	public String getBookName() {
    
    
		return bookName;
	}
	public void setBookName(String bookName) {
    
    
		this.bookName = bookName;
	}
	public String getAuthor() {
    
    
		return author;
	}
	public void setAuthor(String author) {
    
    
		this.author = author;
	}
	public String getSex() {
    
    
		return sex;
	}
	public void setSex(String sex) {
    
    
		this.sex = sex;
	}
	public float getPrice() {
    
    
		return price;
	}
	public void setPrice(float price) {
    
    
		this.price = price;
	}
	public Integer getBookTypeId() {
    
    
		return bookTypeId;
	}
	public void setBookTypeId(Integer bookTypeId) {
    
    
		this.bookTypeId = bookTypeId;
	}
	public String getBookTypeName() {
    
    
		return bookTypeName;
	}
	public void setBookTypeName(String bookTypeName) {
    
    
		this.bookTypeName = bookTypeName;
	}
	public String getBookDesc() {
    
    
		return bookDesc;
	}
	public void setBookDesc(String bookDesc) {
    
    
		this.bookDesc = bookDesc;
	}
	
	
}

Guess you like

Origin blog.csdn.net/bwwork/article/details/113811895