MySQL in WAMP server is used. Database name as supermarket with 5 tables.
Login
Employee
Item_details
Sales
audit
Connection with MySQL and Query Execution
Import JDBC packages. Load and register the JDBC driver. Open a connection to the database. Create a statement object to perform a query. Execute the statement object and return a query resultset. Process the resultset. Close the resultset and statement objects. Close the connection.
Connection Module Coding
import splash.*;import javax.swing.*;
import java.sql.*;
public class Connect extends JFrame {
Connection Conn = null;
PreparedStatement pst = null;
ResultSet rs = null;
public static Connection connectDB() {
Connection con = null;
String url = “jdbc:mysql://localhost:3306/”;
String db = “supermarket”;
String driver = “com.mysql.jdbc.Driver”;
String user = “root”;
String pass = “123”;
try {
Class.forName(driver);
con = DriverManager.getConnection(url + db, user, pass);
if (con == null) {
System.out.println(“Connection cannot be established”);
Admin-Full access to all the resources Sales-Only to sales modules
Interacts with login table and audit table
Connect to database and check if the username, password and type matches with the login If login is success full then user id with timestamp will be entered in audit table
Successful login opens the main form with username
Main Page
Main Page Form
Main interface where user can perform various tasks
MDI form is used in order to contain the jinternal forms Stock-Manage Inventory Sale-Interface to sale items Settings-Employee management
Stock (Item Details)
Stock Item
jInternal form used. jTable is populated with data from item_details table when the for loads Items saved to items_details when pressed saved after filling all text boxes
Sale Form
Sale form
jInternal form used. jTable is populated with data from item_details table when selected in combo box Total calculated in total text box Saved in sale table after pressing cash button
Employee ManagementEmployee Management
jForm used. Employee added to employee table once Insert Button is pressed All the fields should be filled before inserting
Be First to Comment