This tutorial will teach you Simple Sales Inventory System in Java and mysql.this example which will help you to learn the auto no generating using by the code.
Connection con;
PreparedStatement pst;
public void Connect()
{
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/vmproducts","root","");
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
} catch (SQLException ex) {
ex.printStackTrace();
}
} public int getBillNo()
{
int billno = 1;
try {
Statement smt = con.createStatement();
ResultSet rs = smt.executeQuery("select max(billno) from sales");
rs.next();
billno = rs.getInt(1) + 1; // increment by 1 auto ID Set
rs.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
return billno;
} After fill the productname,salesqty,customer click addbutton record will be added in to the database.
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try {
String billno = txtbillno.getText();
String date = txtdate.getText();
String pname = txtpname.getText();
String qty = txtqty.getText();
String customer = txtcustomer.getText();
pst = con.prepareStatement("insert into sales(billno,salesdate,prodname,qty,customer)values(?,?,?,?,?)");
pst.setString(1, billno);
pst.setString(2, date);
pst.setString(3, pname);
pst.setString(4, qty);
pst.setString(5, customer);
int status = pst.executeUpdate();
if(status==1)
{
JOptionPane.showMessageDialog(this, "Sales Completedddddd");
txtpname.setText("");
txtqty.setText("");
txtcustomer.setText("");
txtpname.requestFocus();
txtbillno.setText(String.valueOf(getBillNo())); //after sales successfully Auto ID increment by 1
}
else
{
JOptionPane.showMessageDialog(this, "Sales Failedddd!!!");
}
} catch (SQLException ex) {
ex.printStackTrace();
}
}
What Is the Tesla Pi Phone? Imagine if Tesla, the company that makes famous…
Inventory Management POS systems are now an essential part of modern businesses such as bookshops,…
If you're just beginning to learn Java GUI programming creating an Water System Calculator is a fantastic project for…
GitHub is a powerful tool used by teams and developers around the globe. This guide is…
It's like having a super-smart buddy that is always there to help you write stories,…
The UK is known for its rich history, diverse culture, and most of all its…