Lesson 6
Log In
String sql = "select * from login where User = ? and Password = ?";
try {
st = c.prepareStatement(sql);
st.setString(1, ttt.getText());
st.setString(2, ttt1.getText());
rs = st.executeQuery();
if(rs.next()){
String R = rs.getString("Status");
switch(R){
case "Staff":
No1 P2 = new No1();
P2.setVisible(true);
break;
case "Admin":
InsertProduct P1 = new InsertProduct();
P1.setVisible(true);
break;
default:
JOptionPane.showMessageDialog(null, "Incorrect");
}
// WinClose();
//MainStaff R = new MainStaff();
//R.setVisible(true);
}
else{ JOptionPane.showMessageDialog(null, "Cannnot ");}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, " ");
}
Add TextArea
try{
String sql ="insert into Sell (Item, Price, Amount, Total) values (?, ?, ?, ?)";
st = c.prepareStatement(sql);
st.setString(1, t1.getText());
st.setString(2, t2.getText());
st.setString(3, t3.getText());
st.setString(4, t4.getText());
st.execute();
}
catch(Exception e){JOptionPane.showMessageDialog(null, "Not Save");}
finally {
try {
rs.close();
st.close();
} catch (Exception e) {
}
}
if(1==1){
T.append(
"\n"+t1.getText()+"\t\t"+t2.getText()+"\t\t"+t3.getText()+"\t\t"+t4.getText()+"\n"
);
}
t1.setText("");
t2.setText("");
t3.setText("");
t4.setText("");
String sql = "select * from Sell";
try {
st = c.prepareStatement(sql);
rs = st.executeQuery();
b3.setModel(DbUtils.resultSetToTableModel(rs));
} catch (Exception e) {
}