Results Query System (Java)

xiaoxiao2021-03-06  40

Import java.awt. *; import java.awt.event. *; import java.net. *; import java.sql. *;

class Window extends Frame implements ActionListener {TextArea text; Panel panel; TextField xingming; Button button1, button2; Window () {super ( "query results"); setLayout (new BorderLayout ()); setBackground (Color.cyan); setBounds ( 150, 150, 300, 12; setvisible (TRUE); Text = new textarea (); button1 = new button ("OK"); button2 = New Button ("Query everyone's grades"); xingming = new textfield (16); panel = new TEXTFIELD (16); panel = new Panel (); Panel.Add (New Label) Name: ")); Panel.Add (xingming); panel.add (button1); add (" north ", panel); add (Text , "Center"); add (button2, "South"); text.setEditable (false); text.setBackground (Color.pink); button1.addActionListener (this); button2.addActionListener (this); addWindowListener (new WindowAdapter ( ) {Public void window {setvisible (false); system.exit (0);}}});} public void actionperformed (ActionEvent E) {if (E.getsource () == Button1) {text.setTextText ("check Result: " '/ n'); try {listStudent1 ();} catch (sqlexception ee) {}} else if (E.GetSource () == Button2) {text.setText (" Result of Query ' / n '); try} (SQLEXCEPTION EE) {}}} public void liststudent1 () THROWS SQLIC VOID ListStudent1 () THROWS SQLIC VOID ListStudent1 () Sqlexception {String Name; Int Math, English, Physics, SUM; Try {Class.Forname ("Sun. JDBC.odbc.jdbcodbcdriver ");} catch (classnotfoundexcection e) {} // established JDBC-ODBC Bridge Connection Con = DriverManager.getConnection (" JDBC: ODBC: Redsun ",", ""); // Connect to Database Statement SQL =

Con.createStatement (); // Send SQL statement to the database ResultSet RS = SQL.ExecuteQuery ("Select * from Chengjibiao"); // Handling the result of the query result (rs.next ()) {name = rs.getstring ("Name "); Math = rs.getint (" mathematics "); physics = rs.getint (" physics "); English = rs.getint (" English "); SUM = ENGLISH MATH Physics; IF ((Name.Trim) ()). Equals (xingming.gettext (). Trim ())) {text.append ("***" "/ n" name ":" "/ n" "mathematics:" Math "/ t English:" " " / T physics: " Physics " / T score: " sum '/ n');}}} ((text.getText (). Trim ()). Equals "Query results:")) text.setText ("No this person's grades");} public void liststudent2 () throws sqlexception {string name; int match, English, physics, sum; try {coplass.forname ("Sun. jdbc.odbc.JdbcOdbcDriver ");} catch (ClassNotFoundException e) {} Connection con = DriverManager.getConnection (" jdbc: odbc: redsun "," "," "); Statement sql = con.createStatement (); ResultSet rs = SQL.ExecuteQuery ("Select * from Chengjibiao"); While (rs.next ))) {Name = rs.getstring ("Name"); Math = rs.getint ("Mathematics"); Physics = rs.Getint ("Physics"); English = rs.Getint ("English); Sum = ENGLISH MATH Physics; Text.Append ("***" "/ n" name ":" "/ n" "Mathematics:" Math "English:" ENGLISH "

Physics: " Physics ": " SUM '/ N');}}} public class example}}} public class example23_2 {public static void main (string args []) {window window = new window (); window.pack (); }

转载请注明原文地址:https://www.9cbs.com/read-71351.html

New Post(0)