Add action
public void btninsert_actionperformed (ActionEvent e) {
String name = This.txtName.getText (). Trim ();
String sex = This.txtSex.getText (). Trim ();
String grade = This.txtGrade.getText (). Trim ();
String score = This.txtScore.getText (). Trim ();
if (Name.equals ("") | | Sex.equals ("") | | Grade.equals ("") | |
Score.equals ("")) {
Joptionpane.showmessagedialog (This, "you entered the illegal!");
}
String SqlString = "INSERT into Score values (' + name + ', '" + Sex +
"', '" + Grade + "', '" + score + "');
int rows = db.exeupdate (SqlString);
if (rows = = 0) {
Joptionpane.showmessagedialog (This, "Add failed.") ");
} else {
Joptionpane.showmessagedialog (This, "add success.") ");
}
}
Delete operation
public void btndelect_actionperformed (ActionEvent e) {
String name = This.txtName.getText (). Trim ();
if (Name.equals ("")) {
Joptionpane.showmessagedialog (This, "The data you entered is incomplete");
Return
}
String SqlString = "Delete from Score where name= '" + Name + "'";
int rows = db.exeupdate (SqlString);
if (rows = = 0) {
Joptionpane.showmessagedialog (This, "delete failed");
Return
} else {
Joptionpane.showmessagedialog (This, "delete success");
}
}
Query operations
public void btnselect_actionperformed (ActionEvent e) {
String name = This.txtName.getText (). Trim ();
if (Name.equals ("")) {
Joptionpane.showmessagedialog (This, "search condition is incomplete");
Return
}
String SqlString = "SELECT * from Score where name= '" + name + "'";
Vector rs = db.exequery (SqlString);
if (rs.size () = = 0) {
Joptionpane.showmessagedialog (This, "Find failed");
}
String Sex = ((Vector) rs.get (0)). Get (2). toString ();
String Grade = ((Vector) rs.get (0)). Get (3). ToString ();
String sore = ((Vector) rs.get (0)). Get (4). ToString ();
This.txtSex.setText (SEX);
This.txtGrade.setText (Grade);
This.txtScore.setText (sore);
}
Update action
public void btnupdate_actionperformed (ActionEvent e) {
String name = This.txtName.getText (). Trim ();
String sex = This.txtSex.getText (). Trim ();
String grade = This.txtGrade.getText (). Trim ();
String score = This.txtScore.getText (). Trim ();
if (Name.equals ("") | | Sex.equals ("") | | Grade.equals ("") | |
Score.equals ("")) {
Joptionpane.showmessagedialog (This, "The data you entered is not legal!!");
Return
}
String SqlString = "Update Score set sex= '" + Sex + "', Grade = '" +
Grade + "', score= '" + Score + "' where name= '" +
Name + "'";
int rows = db.exeupdate (SqlString);
if (rows = = 0) {
Joptionpane.showmessagedialog (This, "Update failed!");
} else {
Joptionpane.showmessagedialog (This, "Update successful!");
}
}