In Java to achieve add, delete, change, check function?

Source: Internet
Author: User
Tags gettext

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!");
}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.