This tutorial will teach you to make a Textile Shop Inventory system. The following system will use to manage the Textile Shop Inventory system.
Batch No
The batch no is used to identify the shipping item.i described following table below. i explain clearly.
Batch Table
BatchID | BatchName | CreatedDate |
---|---|---|
1 | B001 | 2020-4-6 |
2 | B002 | 2020-5-10 |
Product Table
Product ID | Product Name | Batch No | Qty | Price |
---|---|---|---|---|
1 | Tshirt | 1 | 100 | 250 |
Above table is explained. Batch table consist of 3 colums batchno,batchname,createddate.consider you have purchased the item for the first item B001 it means batch 1 second time purchased batch changed as B002 it means batch 2.it is very easy to identify the shipping items.when you sell item if you enter the relavent product id. it will display the batches you will able to select your relavent batch for the item.
Establish the database connection
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | Connection con; PreparedStatement pst; ResultSet rs; public void connect() { try { Class.forName("com.mysql.jdbc.Driver"); con = DriverManager.getConnection("jdbc:mysql://localhost/etextileshop","root",""); } catch (ClassNotFoundException ex) { Logger.getLogger(batch.class.getName()).log(Level.SEVERE, null, ex); } catch (SQLException ex) { Logger.getLogger(batch.class.getName()).log(Level.SEVERE, null, ex); } } |
Add Records
you can use the following code snippet to add the records in to database. paste the code inside the save button
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { try { String bname = txtbname.getText(); SimpleDateFormat date_form = new SimpleDateFormat("yyyy-MM-dd"); String date = date_form.format(txtbdate.getDate()); pst = con.prepareStatement("insert into batch(batchname,date)values(?,?)"); pst.setString(1, bname); pst.setString(2, date); int k = pst.executeUpdate(); if(k==1) { JOptionPane.showMessageDialog(this, "Batch Adddeddd"); txtbname.setText(""); txtbname.requestFocus(); } else { JOptionPane.showMessageDialog(this, "Batch Faileddd"); } } catch (SQLException ex) { Logger.getLogger(batch.class.getName()).log(Level.SEVERE, null, ex); } } |
View Records
you can use the following code snippet to retrieve the data stored in the database and present it to users in a proper format. create a method batch_Load().paste the method inside the constructor of the class.when the form is loaded all the records will be shown on the jTable.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | public void batch_Load() { try { pst = con.prepareStatement("select * from batch"); rs = pst.executeQuery(); ResultSetMetaData rsd = rs.getMetaData(); int c; c = rsd.getColumnCount(); DefaultTableModel d = (DefaultTableModel)jTable1.getModel(); d.setRowCount(0); while(rs.next()) { Vector v = new Vector(); for(int i=0; i<c; i++) { v.add(rs.getString("id")); v.add(rs.getString("batchname")); v.add(rs.getString("date")); } d.addRow(v); } } catch (SQLException ex) { Logger.getLogger(batch.class.getName()).log(Level.SEVERE, null, ex); } } |
Form Constructor
1 2 3 4 5 | public batch() { initComponents(); connect(); batch_Load(); } |