You are on page 1of 15

AMRUTVAHINI COLLEGE OF ENGINEERING Sangamner-422608

2021-2022

Department of Computer Engineering

CERTIFICATE
MINI PROJECT ON

“Book Store Management System”


Submitted for the Course of Third Year in Computer Engineering for the Practical

“Database Management system Laboratory”

BY

Aher Shital Sampat (3102)

Bhagwat Priti Pandurang (3110)

Under the Guidance of

Prof. A.S. Thorat


Abstract:

➢ This project report consists of various phases of developing a book store


management system using MySQL and java.
➢ Introduction part gives brief introduction about Bookshop management
system and its operations.
➢ The next part is the REQUIRMENT ANALYSIS which is concerned
with study of various requirements.
➢ The next part is on SYSTEM DESIGN, which include ER diagram.
➢ In next part source code and working model is provided.
➢ Last part is regarding CONCLUSION about above mention project.

Introduction:

This book store management system is developed using Java and


MySQL. It is built to manage basic database functions that are CREATE
RETIEVE UPDATE and DELETE in Eclipse. using Mysql Database. The
INSERT, SELECT, UPDATE and DELETE statements can be used in any
database system, because this is support by all relational database systems.
By entering book name, edition and price and after that clicking on
save button record is saved in database. System will generate ID for each book.
For searching purpose this book ID is used, one can search details of particular
book by using it's ID. In short, The system will be able to record Book details :
name,edition,price. The system will be able to retrieve the Book details :
name,edition,price. Then system will be able to Edit and Delete the Book details
: name,edition,price.
Software Requirement Specification:

➢ JDK 14.0.6 :
• The JDK is a development environment for building applications,
applets, and components using the Java programming language.
• To run this project JDK is necessary.
➢ Eclipse :
• Eclipse is an integrated development environment (IDE) used in
computer programming.its primary use is for developing Java
applications.
• This project is written in eclipse IDE and runs over it.
➢ MySQL :
• MySQL is an open sourcerelational database management system
based on SQL – Structured Query Language.
• MySQL database is necessary for running this project.
➢ MySQL Jconnector :
• MySQL provides connectivity for client applications developed in
the Java programming language with MySQL Connector/J, a driver
that implements the Java Database Connectivity (JDBC) API.
• For establishing connection between MySQL and java MySQL
connector is required.

ER Diagram:

Source Code:
import java.awt.EventQueue;

import javax.swing.JFrame;
import java.awt.Color;
import java.awt.CardLayout;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;

import net.proteanit.sql.DbUtils;

import javax.swing.JLabel;
import javax.swing.JOptionPane;

import java.awt.Font;
import java.awt.SystemColor;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.JScrollPane;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.ActionEvent;
import com.mysql.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.*;
import java.sql.Statement;
import java.sql.SQLDataException;
public class JavaCrud {

private JFrame frmBookShop;


private JTextField txtbname;
private JTextField txtedition;
private JTextField txtprice;
private JTable table;
private JTextField txtbid;

/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
JavaCrud window = new JavaCrud();
window.frmBookShop.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public JavaCrud() {
initialize();
Connect();
table_load();
}

Connection con;
PreparedStatement pat;
ResultSet rs;

public void Connect()


{
try {
Class.forName("com.mysql.cj.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/JavaCrud",
"root","root");
}
catch (ClassNotFoundException ex)
{
ex.printStackTrace();
}
catch (SQLException ex)
{
ex.printStackTrace();
}
}

public void table_load()


{
try
{
pat = con.prepareStatement("select * from book");
rs = pat.executeQuery();
table.setModel(DbUtils.resultSetToTableModel(rs));
}
catch (SQLException e)
{
e.printStackTrace();
}
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frmBookShop = new JFrame();
frmBookShop.getContentPane().setForeground(new Color(0, 0, 0));
frmBookShop.setFont(new Font("Tahoma", Font.BOLD, 30));
frmBookShop.setTitle("Book Shop");
frmBookShop.getContentPane().setBackground(Color.LIGHT_GRAY);
frmBookShop.getContentPane().setLayout(null);

JLabel lblNewLabel = new JLabel("Book Shop");


lblNewLabel.setBounds(353, 10, 194, 85);
lblNewLabel.setBackground(SystemColor.controlHighlight);
lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 30));
frmBookShop.getContentPane().add(lblNewLabel);

JPanel panel = new JPanel();


panel.setBorder(new TitledBorder(null, "Registration", TitledBorder.LEADING,
TitledBorder.TOP, null, null));
panel.setBackground(Color.LIGHT_GRAY);
panel.setBounds(29, 131, 375, 229);
frmBookShop.getContentPane().add(panel);
panel.setLayout(null);

JLabel lblNewLabel_1 = new JLabel("Book Name");


lblNewLabel_1.setFont(new Font("Tahoma", Font.BOLD, 14));
lblNewLabel_1.setBounds(38, 34, 117, 34);
panel.add(lblNewLabel_1);

JLabel lblNewLabel_1_1 = new JLabel("Edition");


lblNewLabel_1_1.setFont(new Font("Tahoma", Font.BOLD, 14));
lblNewLabel_1_1.setBounds(38, 91, 104, 44);
panel.add(lblNewLabel_1_1);

JLabel lblNewLabel_1_2 = new JLabel("Price");


lblNewLabel_1_2.setFont(new Font("Tahoma", Font.BOLD, 14));
lblNewLabel_1_2.setBounds(38, 145, 104, 44);
panel.add(lblNewLabel_1_2);

txtbname = new JTextField();


txtbname.setBounds(153, 42, 212, 26);
panel.add(txtbname);
txtbname.setColumns(10);
txtedition = new JTextField();
txtedition.setColumns(10);
txtedition.setBounds(153, 94, 212, 26);
panel.add(txtedition);

txtprice = new JTextField();


txtprice.setColumns(10);
txtprice.setBounds(153, 148, 212, 26);
panel.add(txtprice);

JButton btnNewButton = new JButton("Save");


btnNewButton.setFont(new Font("Tahoma", Font.BOLD, 14));
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {

String bname,edition,price;
bname = txtbname.getText();
edition = txtedition.getText();
price = txtprice.getText();

try {
pat = con.prepareStatement("insert into book(Name,Edition,Price)values(?,?,?)");
pat.setString(1, bname);
pat.setString(2, edition);
pat.setString(3, price);
pat.executeUpdate();
JOptionPane.showMessageDialog(null, "Record Addedddd!!!!!");
table_load();

txtbname.setText("");
txtedition.setText("");
txtprice.setText("");
txtbname.requestFocus();
}

catch (SQLException e1)


{

e1.printStackTrace();
}
}});

btnNewButton.setBounds(29, 390, 92, 51);


frmBookShop.getContentPane().add(btnNewButton);
JButton btnExit = new JButton("Exit");
btnExit.setFont(new Font("Tahoma", Font.BOLD, 14));

btnExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
btnExit.setBounds(173, 390, 92, 51);
frmBookShop.getContentPane().add(btnExit);

JButton btnClear = new JButton("Clear");


btnClear.setFont(new Font("Tahoma", Font.BOLD, 14));

btnClear.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {

txtbname.setText("");
txtedition.setText("");
txtprice.setText("");
txtbname.requestFocus();
}
});
btnClear.setBounds(312, 390, 92, 51);
frmBookShop.getContentPane().add(btnClear);

JScrollPane scrollPane = new JScrollPane();


scrollPane.setBounds(427, 129, 388, 312);
frmBookShop.getContentPane().add(scrollPane);

table = new JTable();


scrollPane.setViewportView(table);

JPanel panel_1 = new JPanel();


panel_1.setBorder(new TitledBorder(null, "Search", TitledBorder.LEADING, TitledBorder.TOP,
null, null));
panel_1.setBounds(35, 472, 369, 65);
frmBookShop.getContentPane().add(panel_1);
panel_1.setLayout(null);

JLabel lblNewLabel_2 = new JLabel("Book ID");


lblNewLabel_2.setFont(new Font("Tahoma", Font.BOLD, 14));
lblNewLabel_2.setBounds(10, 24, 106, 31);
panel_1.add(lblNewLabel_2);

txtbid = new JTextField();


txtbid.setColumns(10);
txtbid.addKeyListener(new KeyAdapter() {

public void keyReleased(KeyEvent e) {


try {

String id = txtbid.getText();

pat = con.prepareStatement("select name,edition,price from book where id = ?");


pat.setString(1, id);
ResultSet rs = pat.executeQuery();

if(rs.next()==true)
{

String name = rs.getString(1);


String edition = rs.getString(2);
String price = rs.getString(3);

txtbname.setText(name);
txtedition.setText(edition);
txtprice.setText(price);

}
else
{
txtbname.setText("");
txtedition.setText("");
txtprice.setText("");

}
}
catch (SQLException ex) {

}
}});

txtbid.setBounds(147, 29, 212, 26);


panel_1.add(txtbid);
JButton btnUpdate = new JButton("Update");
btnUpdate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
String bname,edition,price,bid;
bname = txtbname.getText();
edition = txtedition.getText();
price = txtprice.getText();
bid = txtbid.getSelectedText();
try {
pat = con.prepareStatement("update book set name= ?,edition=?,price=? where
id =?");
pat.setString(1, bname);
pat.setString(2, edition);
pat.setString(3, price);
pat.setString(4, bid);
pat.executeUpdate();
JOptionPane.showMessageDialog(null, "Record Updatedddd!!!!!");
table_load();

txtbname.setText("");
txtedition.setText("");
txtprice.setText("");
txtbname.requestFocus();
}

catch (SQLException e1)


{

e1.printStackTrace();
}
}});
btnUpdate.setFont(new Font("Tahoma", Font.BOLD, 14));
btnUpdate.setBounds(476, 472, 128, 65);
frmBookShop.getContentPane().add(btnUpdate);

JButton btnDelete = new JButton("Delete");


btnDelete.setFont(new Font("Tahoma", Font.BOLD, 14));

btnDelete.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

String bid;
bid = txtbid.getText();

try {
pat = con.prepareStatement("delete from book where id =?");

pat.setString(1, bid);
pat.executeUpdate();
JOptionPane.showMessageDialog(null, "Record Delete!!!!!");
table_load();

txtbname.setText("");
txtedition.setText("");
txtprice.setText("");
txtbname.requestFocus();
}

catch (SQLException e1) {

e1.printStackTrace();
}
}});

btnDelete.setBounds(648, 472, 128, 65);


frmBookShop.getContentPane().add(btnDelete);

frmBookShop.setBounds(100, 100, 859, 584);


frmBookShop.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}}
Working model:

Adding a Record:
Updating a Record:
Deleting a Record:

Conclusion:

The goal of Book Store management system is to offer more convenience and
more efficiency to access data from database.
Achievements :
➢ Database design.
➢ Understanding connectivity between java and MySQL.
➢ Performing CRUD operations.

You might also like