Cet article partage avec vous la mise en œuvre du système de gestion des étudiants basée sur MySQL pour votre référence. Le contenu spécifique est le suivant
Parce que le laboratoire a dû remettre les devoirs, il a construit un système de gestion des étudiants et a publié un code pour le commémorer. L'interface et d'autres choses étaient trop urgentes étaient pauvres.
Il y a encore de petits détails qui ne sont pas parfaits, mais qui peuvent toujours atteindre les fonctions principales.
La fenêtre est l'interface principale
package d'abord; Importer java.sql. *; import java.awt. *; import java.awt.event. *; importer javax.swing. *; Public Class Window {public static void main (String [] args) {jframe jframe = new JFrame ("Student Management System"); // Dimension de la fenêtre D = nouvelle dimension (400,300); Point P = nouveau point (250,350); JFrame.SetSize (D); jframe.setLocation (p); jframe.setDefaultCloseOperation (jframe.exit_on_close); jFrame.setVisible (true); JBUTTON Button1 = new JBUTTON ("ADD"); JBUTTON Button2 = new JBUTTON ("Modifier"); JBUTTON Button3 = new JBUTTON ("Query"); JBUTTON Button4 = new JBUTTON ("Delete"); JBUTTON Button5 = new Jbutton ("Browse"); FlowLayout Flow = new FlowLayout (FlowLayout.left, 10,10); JPANEL PANNEL = NOUVEAU JPANEL (FLOW); PANNEL.ADD (Button1); PANNEL.ADD (Button2); PANNEL.ADD (Button3); PANNEL.ADD (Button4); PANNEL.ADD (Button5); jframe.add (panneau); Button1.AddActionListener (new ActionListener () {public void ActionPerformed (ActionEvent e) {add add = new Add ();}}); Button2.AddActionListener (new ActionListener () {public void ActionPerformed (ActionEvent e) {Change Change = new Change ();}}); Button3.AddActionListener (new ActionListener () {public void ActionperFormed (ActionEvent e) {askyk = new ASK ();}}); Button4.AddActionListener (new ActionListener () {public void ActionPerformed (ActionEvent e) {Delete Delete = new Delete ();}}); Button5.AddActionListener (new ActionListener () {public void ActionPerformed (ActionEvent e) {look look = new look ();}}); }}Ajouter est ajouté
package d'abord; Importer java.sql. *; import java.awt. *; import java.awt.event. *; importer javax.swing. *; import com.mysql.jdbc.Driver; Importer First.Window; La classe publique Add étend JFrame {private static final long SerialVersionUID = -1928970409928880648l; JLabel jlNumber = new JLabel ("Numéro d'étudiant:"); JLabel jlName = new JLabel ("name:"); JLabel jlSEX = new JLabel ("Gender:"); JLabel jlbirthday = new JLabel ("Date de naissance:"); JLABEL JLDPARTMENT = NOUVEAU JLABEL ("Collège:"); JTextfield jtNumber = new JTextfield ("", 20); JTextfield jtname = new JTextField ("", 20); JTextfield jtsex = new JTextfield ("", 20); JTextfield jtbirthday = new JTextfield ("", 20); JTextfield jtdepartment = new JTextfield ("", 20); JBUTTON BUTTITADD = NOUVEAU JBUTTON ("ADD"); JBUTTON ButtonReturn = new JBUTTON ("retour"); public add () {jpanel jpnumber = new JPanel (); Jpanel jpname = new JPanel (); Jpanel jpsex = new JPanel (); Jpanel jpbirthday = new JPanel (); Jpanel jpdepartment = new JPanel (); Jpanel jpforbutton = new JPanel (new GridLayout (1,1)); jpnumber.add (jlNumber); jpnumber.add (jtnumber); jpname.add (jlName); jpname.add (jtname); jpsex.add (jlsex); jpsex.add (jtsex); jpbirthday.add (jlbirthday); jpbirthday.add (jtbirthday); jpdePartment.add (JLDPartement); jpforbutton.add (ButtonAdd); jpforbutton.add (boutonreturn); ButtonAdd.AddActionListener (new ActionListener () {public void ActionPerformed (ActionEvent e) {// Ajouter une connexion conn = null; instruction stat = null; préparéStation ps = null; String sql = "insert dans l'étudiant (nombre, nom, sexe, anniversaire, département)" + "valeurs"); System.out.println ("JBDC chargé avec succès!");} Catch (exception a) {System.out.println ("JBDC Dog Belt!"); PS = Conn.Preparestatement (SQL); Ps.SetString (5, jtdepartment.getText); (SQLEXception b) {B.PrintStackTrace ();} boutonreturn.addactionListener (new ActionListener () {public void ActionPerformed (actionEvent e) {window window = new Window ();}}); this.setTitle ("Ajouter des informations sur les étudiants"); this.setLayout (new GridLayout (9,1)); this.add (jpnumber); this.add (jpname); this.add (jpSex); this.add (jpbirthday); this.add (jpdepartment); this.add (jpforbutton); this.setLocation (400 300); this.setSize (350 300); this.setVisible (true); }}Demandez à une question
package d'abord; Importer java.sql. *; import java.awt. *; import java.awt.event. *; importer javax.swing. *; Importer First.Window; La classe publique Ask étend JFrame {private static final long SerialVersionUID = -1928970409928880648l; JLabel jlNumber = new JLabel ("Numéro d'étudiant:"); JLabel jlName = new JLabel ("name:"); JLabel jlSEX = new JLabel ("Gender:"); JLabel jlbirthday = new JLabel ("Date de naissance:"); JLABEL JLDPARTMENT = NOUVEAU JLABEL ("Collège:"); JTextfield jtNumber = new JTextfield ("", 20); JLabel jName = new JLabel (); JLabel jSEX = new JLabel (); JLabel jbirthday = new JLabel (); JLabel jDepartment = new JLabel (); JBUTTON Buttonask = new JBUTTON ("Query"); JBUTTON ButtonReturn = new JBUTTON ("retour"); public Ask () {jpanel jpnumber = new JPanel (); Jpanel jpname = new JPanel (); Jpanel jpsex = new JPanel (); Jpanel jpbirthday = new JPanel (); Jpanel jpdepartment = new JPanel (); Jpanel jpforbutton = new JPanel (new GridLayout (1,1)); jpnumber.add (jlNumber); jpnumber.add (jtnumber); jpname.add (jlName); jpname.add (jname); jpsex.add (jlsex); jpsex.add (jsex); jpbirthday.add (jlbirthday); jpbirthday.add (jbirthday); jpdePartment.add (JLDPartement); jpdePartment.add (jDepartment); jpforbutton.add (boutonreturn); Buttonask.AdDactionListener (new ActionListener () {public void ActionPerformed (ActionEvent e) {connexion conn = null; resultSet res = null; instruction stat = null; string sql = "Select Number, Name, Sex, Department from Student;" System.out.Println ("JDBC Fall"); D.PrintStackTrace (); (res.next ()) {if (res.getString (1) .equals (jtNumber.getText ()))) {jName.seTText (res.getString (2)); JSEX.SETTEXT (res.getString (3)); jBirthday.seTText (res.getString (4)); jDepartment.seTText (res.getString (5)); casser; }}} catch (sqlexception e1) {// TODO Block de catch généré automatiquement e1.printStackTrace (); } enfin {try {conn.close (); } catch (sqlexception ar) {ar.printStackTrace (); }}}}); boutonreturn.addactionListener (new ActionListener () {public void ActionPerformed (actionEvent e) {window window = new Window ();}}); this.setTitle ("Information des étudiants de requête"); this.setLayout (new GridLayout (9,1)); this.add (jpnumber); this.add (jpname); this.add (jpSex); this.add (jpbirthday); this.add (jpdepartment); this.add (jpforbutton); this.setLocation (400 300); this.setSize (350 300); this.setVisible (true); }}Le changement est modifié
package d'abord; Importer java.sql. *; import java.awt. *; import java.awt.event. *; importer javax.swing. *; Importer First.Window; Le changement de classe publique étend JFrame {private static final long SerialVersionUID = -1928970409928880648l; JLabel jlNumber = new JLabel ("Numéro d'étudiant:"); JLabel jlName = new JLabel ("name:"); JLabel jlSEX = new JLabel ("Gender:"); JLabel jlbirthday = new JLabel ("Date de naissance:"); JLABEL JLDPARTMENT = NOUVEAU JLABEL ("Collège:"); JTextfield jtNumber = new JTextfield ("", 20); JTextfield jtname = new JTextField ("", 20); JTextfield jttsex = new JTextfield ("", 20); JTextfield jtbirthday = new JTextfield ("", 20); JTextfield jtdepartment = new JTextfield ("", 20); JBUTTON ButtonChange = new JBUTTON ("Modifier"); JBUTTON ButtonReturn = new JBUTTON ("retour"); public change () {jpanel jpnumber = new JPanel (); Jpanel jpname = new JPanel (); Jpanel jpsex = new JPanel (); Jpanel jpbirthday = new JPanel (); Jpanel jpdepartment = new JPanel (); Jpanel jpforbutton = new JPanel (new GridLayout (1,1)); jpnumber.add (jlNumber); jpnumber.add (jtnumber); jpname.add (jlName); jpname.add (jtname); jpsex.add (jlsex); jpsex.add (jtsex); jpbirthday.add (jlbirthday); jpbirthday.add (jtbirthday); jpdePartment.add (JLDPartement); jpdepartment.add (jtdepartment); jpforbutton.add (boutonreturn); ButtonChange.AddActionListener (new ActionListener () {public void ActionPerformed (ActionEvent e) {String Number = JTNumber.getText (); String name = jtName.getText (); String Sex = JTTSEX.getText (); String anniversaire = jtbirthday.getText (). = null; Conn = driverManager.getConnection ("jdbc: mysql: // localhost: 3306 / javastu", "root", "123"); {try {class.forname (com.mysql.jdbc.driver ");} Catch (exception d) {System.out.println (JDBC Fall"); sexe = '"+ sexe +"' où numéro = '"+ jtNumber.getText () +"' "; String sql4 =" Update Student set anniversaire = '"+ anniversaire +"' where number = '"+ jtNumber.getText () +"' "; String sql5 =" update Student set Department = '";"; Try {tessor {tessor {tessor {tessor {tessor {tessor {"where ='" + jtnumber.gettext () + "";; Conn = DriverManager.getConnection ("JDBC: MySQL: // localhost: 3306 / javastu", "root", "123"); STAT.EXECUTEUPDATE (SQL5);} Catch (SQLEXCTION G) {// TODO BLOCK GÉNÉRIEUR AUTO Bloc de capture généré par Auto E1.PrintStackTrace ();} Enfin {Try {Conn.Close (); boutonreturn.addactionListener (new ActionListener () {public void ActionPerformed (actionEvent e) {window window = new Window ();}}); this.setTitle ("Modifier les informations de l'élève"); this.setLayout (new GridLayout (9,1)); this.add (jpnumber); this.add (jpname); this.add (jpSex); this.add (jpbirthday); this.add (jpdepartment); this.add (jpforbutton); this.setLocation (400 300); this.setSize (350 300); this.setVisible (true); }}Supprimer est supprimé
package d'abord; Importer java.sql. *; import java.awt. *; import java.awt.event. *; importer javax.swing. *; Importer First.Window; La classe publique Delete étend JFrame {private static final long SerialVersionUID = -1928970409928880648l; JLabel jlNumber = new JLabel ("Numéro d'étudiant:"); JTextfield jtNumber = new JTextfield ("", 20); JBUTTON BUTTONDELETE = NOUVEAU JBUTTON ("DELETE"); JBUTTON ButtonReturn = new JBUTTON ("retour"); public Delete () {jpanel jpnumber = new JPanel (); Jpanel jpforbutton = new JPanel (new GridLayout (1,1)); jpnumber.add (jlNumber); jpnumber.add (jtnumber); jpforbutton.add (ButtondElete); jpforbutton.add (boutonreturn); ButtonDelete.AddactionListener (new ActionListener () {public void ActionPerformed (ActionEvent e) {String Number = JtNumber.getText (); Connection Conn = Null; ResultSet Res = Null; Statement Stat = Null; String Sql = "Delete from Student Where Number = '" + Number + "'; Try {class.forname (" com.mysqL.jdbc.); } Catch (exception a) {A.PrintStackTrace (); H.PrintstackTrace ();} Enfin {Try {Conn.Close (); boutonreturn.addactionListener (new ActionListener () {public void ActionPerformed (actionEvent e) {window window = new Window ();}}); this.setTitle ("Supprimer les informations des étudiants"); this.setLayout (new GridLayout (9,1)); this.add (jpnumber); this.add (jpforbutton); this.setLocation (400 300); this.setSize (350 300); this.setVisible (true); }}Regarder est la navigation
package d'abord; Importer java.sql. *; import java.awt. *; import java.awt.event. *; importer javax.swing. *; import java.util. *; Importer First.Window; La classe publique Look étend JFrame {private static final long SerialVersionUID = -1928970409928880648l; Connexion conn = null; PréparedStatement PS = null; ResultSet res = null; // JBUTTON Buttonlook = new JButton ("Browse"); // JBUTTON ButtonReturn = new JBUTTON ("retour"); JTable JTable; Jscrollpane jscrollpane = new jscrollpane (); Vector ColumnNames = null; Vector rowData = null; public look () {jpanel jpforbutton = new JPanel (new GridLayout (1,1)); ColumnNames = new Vector (); ColumnNames.Add ("Numéro d'étudiant"); colmnNames.add ("name"); ColumnNames.Add ("Gender"); ColumnNames.Add ("Date de naissance"); ColumnNames.Add ("College"); RowData = new Vector (); //jpforbutton.add(buttonlook); //jpforbutton.add(buttonreturn); essayez {class.forname ("com.mysql.jdbc.driver"); Conn = driverManager.getConnection ("jdbc: mysql: // localhost: 3306 / javastu", "root", "123"); ps = conn.preparestatement ("SELECT * FROM Student"); res = ps.ExecuteQuery (); while (res.next ()) {vector hang = new vector (); hang.add (res.getString (1)); hang.add (res.getString (2)); hang.add (res.getString (3)); hang.add (res.getString (4)); hang.add (res.getString (5)); RowData.Add (Hang); } System.out.println ("Load OK!"); } catch (exception q) {q.printStackTrace (); System.out.println ("Go Die"); } enfin {try {res.close (); ps.close (); conn.close (); System.out.println ("Close OK"); } catch (sqlexception o) {o.printStackTrace (); System.out.println ("Go Die 2"); }} jTable = new JTable (RowData, ColumnNames); jscrollPane = new JscrollPane (jTable); this.add (jscrollpane); this.setTitle ("Browse Student Information"); this.setLayout (new GridLayout (2,5)); this.add (jpforbutton); this.setLocation (300 300); this.setSize (500 300); this.setVisible (true); this.setResiSable (false); }}Quelques interfaces en cours:
Pour plus de matériel d'apprentissage, veuillez faire attention au sujet spécial «développement du système de gestion».
Ce qui précède est tout le contenu de cet article. J'espère que cela sera utile à l'apprentissage de tous et j'espère que tout le monde soutiendra davantage Wulin.com.