NirmalKanagasabai / Inventory_Management_System

Simple 'inventory management' application to test out the functionality of JDBC with MySQL as back-end. The project makes use of Data Access Object (DAO) design pattern to provide specific data operations and hide the details of the underlying database.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Inventory Management System

This repository contains a simple inventory management system. It has the following functionalities:

  • Adding a new item to the inventory
  • Get the details of a specific item
  • Get the details of all the items in the inventory
Item getItemDetails (int id);

void addNewItem (Item newItem);

List<Item> getAllItems ();

Implementation Details

  • Programming Language: Java
  • API: Java DataBase Connectivity (JDBC)
  • Back-end (Relational Database): MySQL
  • Design Pattern: Data Access Object (DAO)

7 Steps Involved in JDBC

1) Importing Java package

import java.sql.*;

2) Load and Register the Driver

Class.forName("com.mysql.jdbc.Driver");

3) Establishing the connection to the database

connection = DriverManager.getConnection(url, userName, password);

4) Preparing a Statement (or Prepared Statement or Callable Statement)

// Statement
String staticQuery = "select * from inventory";
Statement statement = connection.createStatement(); 

// Prepared Statement
String dynamicQuery = "select * from inventory where itemID = ?";
PreparedStatement preparedStatement = connection.prepareStatemnt(dynamicQuery);
preparedStatement.setInt(1, id);

5. Executing the Statement

// Statement
ResultSet rs = statement.executeQuery(selectAllQuery);

// PreparedStatement
ResultSet resultSet = preparedStatement.executeQuery();

6. Processing the Result

while (resultSet.next()) {
	item.setItemID(resultSet.getInt(1));
	item.setItemName(resultSet.getString(2));
	item.setItemCompany(resultSet.getString(3));
	item.setItemCategory(resultSet.getString(4));
	item.setItemPrice(resultSet.getLong(5));
}

7. Terminating the Statement & Connection

statement.close();
preparedStatement.close();

connection.close();

// Note: Use try-catch block to capture the exceptions

References

About

Simple 'inventory management' application to test out the functionality of JDBC with MySQL as back-end. The project makes use of Data Access Object (DAO) design pattern to provide specific data operations and hide the details of the underlying database.


Languages

Language:Java 100.0%