Java implements the student management system based on MySQL and the mysql student management system

Source: Internet
Author: User

Java implements the student management system based on MySQL and the mysql student management system

This article shares with you the Java student management system based on MySQL for your reference. The specific content is as follows:

Because the lab had to hand in homework and then built a student management system, and pasted a code to commemorate it, the interface was too urgent and something worse.

Some small details are incomplete, but the main functions can still be implemented.

Window is the main interface

Package First; import java. SQL. *; import java. awt. *; import java. awt. event. *; import javax. swing. *; public class Window {public static void main (String [] args) {JFrame jframe = new JFrame ("student management system "); // window Dimension d = new Dimension (400,300); Point p = new Point (250,350); jframe. setSize (d); jframe. setLocation (p); jframe. setdefaclocloseoperation (JFrame. EXIT_ON_CLOSE); jframe. setVisible (true); JButton button1 = new JButton ("add"); JButton button2 = new JButton ("modify"); JButton button3 = new JButton ("query "); JButton button4 = new JButton ("delete"); JButton button5 = new JButton ("Browse"); FlowLayout flow = new FlowLayout (FlowLayout. LEFT, 10, 10); JPanel = new JPanel (flow); panel. add (button1); panel. add (button2); panel. add (button3); panel. add (button4); panel. add (button5); jframe. add (panel); button1.addActionListener (new ActionListener () {public void actionreceivmed (ActionEvent e) {Add add = new Add () ;}}); button2.addActionListener (new ActionListener () {public void action=med (ActionEvent e) {Change change Change = new Change () ;}}); button3.addActionListener (new ActionListener () {public void action=med (ActionEvent e) {Ask ask = new Ask () ;}}); button4.addActionListener (new ActionListener () {public void actionreceivmed (ActionEvent e) {Delete delete = new Delete ();}}); button5.addActionListener (new ActionListener () {public void actionreceivmed (ActionEvent e) {Look look = new Look ();}});}}

Add is to Add

Package First; import java. SQL. *; import java. awt. *; import java. awt. event. *; import javax. swing. *; import com. mysql. jdbc. driver; import First. window; public class Add extends JFrame {private static final long serialVersionUID =-1928970409928880648L; JLabel jlnumber = new JLabel ("student ID:"); JLabel jlname = new JLabel ("name: "); JLabel jlsex = new JLabel (" Gender: "); JLabel jlbirthday = new JLabel (" Date of Birth: "); J Label jldepartment = new JLabel (":"); 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 buttonadd = new JButton ("Add"); JButton buttonreturn = new JButton ("return"); public Add () {JPanel jpnumber = new JPanel (); JPanel Jpname = new JPanel (); JPanel jname x = 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); j1_x. add (jlsex); j1_x. add (jtsex); jpbirthday. add (jlbirthday); jpbirthday. add (jtbirthday); jpdepartment. add (jldepartment); jpdepartmen T. add (jtdepartment); jpforbutton. add (buttonadd); jpforbutton. add (buttonreturn); buttonadd. addActionListener (new ActionListener () {public void actionreceivmed (ActionEvent e) {// Add Connection conn = null; Statement stat = null; PreparedStatement ps = null; string SQL = "INSERT INTO student (number, name, sex, birthday, department)" + "values (?,?,?,?,?) "; Try {Class. forName (" Driver "); System. out. println (" JBDC loaded successfully! ");} Catch (Exception a) {System. out. println (" JBDC dog belt! ");. PrintStackTrace ();} try {conn = DriverManager. getConnection ("jdbc: mysql: // localhost: 3306/javaStu", "root", "123"); ps = conn. prepareStatement (SQL); ps. setString (1, jtnumber. getText (); ps. setString (2, jtname. getText (); ps. setString (3, jtsex. getText (); ps. setString (4, jtbirthday. getText (); ps. setString (5, jtdepartment. getText (); ps.exe cuteUpdate (); // System. out. println ("MySQL connection successful! "); // Stat = conn. createStatement (); // stat.exe cuteUpdate (SQL); // System. out. println (" data inserted successfully! ");} Catch (SQLException B) {B. printStackTrace ();} finally {try {conn. close (); System. out. println ("MySQL disabled successfully");} catch (SQLException c) {System. out. println ("MySQL failed to close"); c. printStackTrace () ;}}}); buttonreturn. addActionListener (new ActionListener () {public void actionreceivmed (ActionEvent e) {Window window Window = new Window () ;}}); this. setTitle ("add student information"); 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 );}}

Ask is a query

Package First; import java. SQL. *; import java. awt. *; import java. awt. event. *; import javax. swing. *; import First. window; public class Ask extends JFrame {private static final long serialVersionUID =-1928970409928880648L; JLabel jlnumber = new JLabel ("student ID:"); JLabel jlname = new JLabel ("name: "); JLabel jlsex = new JLabel (" Gender: "); JLabel jlbirthday = new JLabel (" Date of Birth: "); JLabel jldepartment = new JLabel (" :"); 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 ("return"); public Ask () {JPanel jpnumber = new JPanel (); JPanel jpname = new JPanel (); JPanel x = 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); j1_x. add (jlsex); j1_x. add (jsex); jpbirthday. add (jlbirthday); jpbirthday. add (jbirthday); jpdepartment. add (jldepartment); jpdepartment. add (jdepartment); jpforbutton. add (buttonask); jpforbutton. add (buttonreturn); buttonask. addActionListener (new ActionListener () {public void actionreceivmed (ActionEvent e) {Connection conn = null; ResultSet res = null; Statement stat = null; String SQL = "SELECT number, name, sex, birthday, department FROM student; "; try {Class. forName ("com. mysql. jdbc. driver ");} catch (Exception d) {System. out. println ("jdbc fall"); d. printStackTrace ();} try {conn = DriverManager. getConnection ("jdbc: mysql: // localhost: 3306/javaStu", "root", "123"); stat = conn. createStatement (); res=stat.exe cuteQuery (SQL); while (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); break ;}} catch (SQLException e1) {// TODO Auto-generated catch block e1.printStackTrace ();} finally {try {conn. close ();} catch (SQLException ar) {ar. printStackTrace () ;}}}); buttonreturn. addActionListener (new ActionListener () {public void actionreceivmed (ActionEvent e) {Window window Window = new Window () ;}}); this. setTitle ("querying student information"); 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 );}}

Change is Modification

Package First; import java. SQL. *; import java. awt. *; import java. awt. event. *; import javax. swing. *; import First. window; public class Change extends JFrame {private static final long serialVersionUID =-1928970409928880648L; JLabel jlnumber = new JLabel ("student ID:"); JLabel jlname = new JLabel ("name: "); JLabel jlsex = new JLabel (" Gender: "); JLabel jlbirthday = new JLabel (" Date of Birth: "); JLabel jldepartment = new JLabel (" :"); 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 buttonchange = new JButton ("modify "); JButton buttonreturn = new JButton ("return"); 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); j1_x. add (jlsex); j1_x. add (jtsex); jpbirthday. add (jlbirthday); jpbirthday. add (jtbirthday); jpdepartment. add (jldepartment); jpdepartment. add (jtdepartment); jpforbutton. add (buttonchange); jpforbutton. add (buttonreturn); buttonchange. addActionListener (new ActionListener () {public void actionreceivmed (ActionEvent e) {String number = jtnumber. getText (); String name = jtname. getText (); String sex = jtsex. getText (); String birthday = jtbirthday. getText (); String department = jtdepartment. getText (); Connection conn = null; ResultSet res = null; Statement stat = null; String SQL = "SELECT number, name, sex, birthday, department FROM student ;"; try {Class. forName ("com. mysql. jdbc. driver ");} catch (Exception d) {System. out. println ("jdbc fall"); d. printStackTrace ();} try {conn = DriverManager. getConnection ("jdbc: mysql: // localhost: 3306/javaStu", "root", "123"); stat = conn. createStatement (); res=stat.exe cuteQuery (SQL); while (res. next () {// change if (res. getString (1 ). equals (jtnumber. getText () {try {Class. forName ("com. mysql. jdbc. driver ");} catch (Exception d) {System. out. println ("jdbc fall"); d. printStackTrace ();} String sql2 = "UPDATE student SET name = '" + name + "'where number ='" + jtnumber. getText () + "'"; String sql3 = "UPDATE student SET sex ='" + sex + "'where number = '" + jtnumber. getText () + "'"; String sql4 = "UPDATE student SET birthday ='" + birthday + "'where number = '" + jtnumber. getText () + "'"; String sql5 = "UPDATE student SET department ='" + department + "'where number = '" + jtnumber. getText () + "'"; try {conn = DriverManager. getConnection ("jdbc: mysql: // localhost: 3306/javaStu", "root", "123"); stat = conn. createStatement (); stat.exe cuteUpdate (sql2); stat.exe cuteUpdate (sql3); stat.exe cuteUpdate (sql4); stat.exe cuteUpdate (sql5);} catch (SQLException g) {// TODO Auto-generated catch block g. printStackTrace ();} try {stat. close (); conn. close ();} catch (SQLException ar) {ar. printStackTrace ();} break;} // change end} catch (SQLException e1) {// TODO Auto-generated catch block e1.printStackTrace ();} finally {try {conn. close ();} catch (SQLException ar) {ar. printStackTrace () ;}}}); buttonreturn. addActionListener (new ActionListener () {public void actionreceivmed (ActionEvent e) {Window window Window = new Window () ;}}); this. setTitle ("Modify student information"); 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 );}}

Delete is Delete

Package First; import java. SQL. *; import java. awt. *; import java. awt. event. *; import javax. swing. *; import First. window; public class Delete extends JFrame {private static final long serialVersionUID =-1928970409928880648L; JLabel jlnumber = new JLabel ("student ID:"); JTextField jtnumber = new JTextField ("", 20); JButton buttondelete = new JButton ("delete"); JButton buttonreturn = new JButton ("return"); public De Lete () {JPanel jpnumber = new JPanel (); JPanel jpforbutton = new JPanel (new GridLayout (1, 1); jpnumber. add (jlnumber); jpnumber. add (jtnumber); jpforbutton. add (buttondelete); jpforbutton. add (buttonreturn); buttondelete. addActionListener (new ActionListener () {public void actionreceivmed (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. driver ");} catch (Exception a) {. printStackTrace ();} try {conn = DriverManager. getConnection ("jdbc: mysql: // localhost: 3306/javaStu", "root", "123"); stat = conn. createStatement (); stat.exe cuteUpdate (SQL);} catch (SQLException h) {h. printStackTrace ();} finally {try {conn. close (); System. out. println ("c Lose success! ");} Catch (SQLException j) {System. out. println (" close go die! "); J. printStackTrace () ;}}}); buttonreturn. addActionListener (new ActionListener () {public void actionreceivmed (ActionEvent e) {Window window Window = new Window () ;}}); this. setTitle ("delete student information"); this. setLayout (new GridLayout (9, 1); this. add (jpnumber); this. add (jpforbutton); this. setLocation (400,300); this. setSize (350,300); this. setVisible (true );}}

Look is browsing

Package First; import java. SQL. *; import java. awt. *; import java. awt. event. *; import javax. swing. *; import java. util. *; import First. window; public class Look extends JFrame {private static final long serialVersionUID =-1928970409928880648L; Connection conn = null; PreparedStatement ps = null; ResultSet res = null; // JButton buttonlook = new JButton (""); // JButton buttonreturn = new JButton ("Return "); 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 ("student ID"); columnNames. add ("name"); columnNames. add ("gender"); columnNames. add ("Date of Birth"); columnNames. add (""); rowData = new Vector (); // jpforbutton. add (buttonlook); // jpforbutton. ad D (buttonreturn); try {Class. forName ("com. mysql. jdbc. driver "); conn = DriverManager. getConnection ("jdbc: mysql: // localhost: 3306/javaStu", "root", "123"); ps = conn. prepareStatement ("SELECT * FROM student"); res = ps.exe cuteQuery (); 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 (r Es. getString (5); rowData. add (hang);} System. out. println ("load OK! ");} Catch (Exception q) {q. printStackTrace (); System. out. println ("go die");} finally {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. setResizable (false );}}

Some running interfaces:

For more information, see management system development.

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

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.