private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
DefaultListModel list = (DefaultListModel) jList1.getModel();
String sql = "Select * from salesorder";
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/userauthentication", "root", "");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
Integer id = rs.getInt("id");
list.addElement(id);
}
jList1.setModel(list);
} catch (Exception e) {
JOptionPane.showMessageDialog(this, e.getMessage());
}
}
private void jList1MouseClicked(java.awt.event.MouseEvent evt) {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/userauthentication", "root", "");
Statement stmt = con.createStatement();
Integer no = (Integer) jList1.getSelectedValue();
String sql1 = "Select * from salesorder where id= '" + (no) + "'";
ResultSet rs = stmt.executeQuery(sql1);
while (rs.next()) {
Integer id = rs.getInt("id");
String Brand = rs.getString("Brand");
String Product = rs.getString("Product");
String Model = rs.getString("Model");
Integer Quantity = rs.getInt("Quantity");
Double Price = rs.getDouble("Price");
String Customer = rs.getString("Customer");
Date date = rs.getDate("Date");
jTextField8.setText("" + id);
jTextField1.setText("" + Brand);
jTextField2.setText("" + Product);
jTextField3.setText("" yyyy-mm-dd);
jTextField4.setText("" + Model);
jTextField5.setText("" + Quantity);
jTextField6.setText("" + Price);
jTextField7.setText("" + Customer);
}
} catch (Exception e) {
JOptionPane.showMessageDialog(this, e.getMessage());
}// TODO add your handling code here:
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/userauthentication", "root", "");
Statement stmt = con.createStatement();
Integer no = (Integer) jList1.getSelectedValue();
Integer id = Integer.parseInt(jTextField8.getText());
String Brand = jTextField1.getText();
String Model = jTextField4.getText();
String Customer = jTextField7.getText();
String Product = jTextField2.getText();
Integer Quantity = Integer.parseInt(jTextField5.getText());
String Date = jTextField3.getText();
Double Price = Double.parseDouble(jTextField6.getText());
String sql1 = "Update salesorder set id='" + (id) + "', Brand='" + (Brand) + "', Model='" + (Model) + "', Customer='" + (Customer) + "', Product='" + (Product) + "', Quantity='" + (Quantity) + "',Price='" + (Price) + "', Date='" + (Date) + "' where id = '" + (no) + "'";
stmt.executeUpdate(sql1);
} catch (Exception e) {
JOptionPane.showMessageDialog(this, e.getMessage());
}