/*
* Function:
* Completes the student management system of the mini version.
*/
Import java. AWT .*;
Import javax. Swing .*;
Import java. SQL .*;
Import java. util .*;
Public class sms_1 extends jframe {
// Define the control:
Jpanel jp1, JP2;
Jtable JT;
Jbutton jb1, jb2, jb3, jb4;
Jscrollpane JSP = NULL;
Jtextfield JTF;
// Define the variables required for database operations
Preparedstatement PS = NULL;
Connection Ct = NULL;
Resultset rs = NULL;
Vector columnnames = NULL;
Vector rowdata = NULL;
Public static void main (string [] ARGs ){
Sms_1 SMS = new sms_1 ();
}
Public sms_1 (){
// Column name
Columnnames = new vector ();
Columnnames. Add ("student ID ");
Columnnames. Add ("name ");
Columnnames. Add ("gender ");
Columnnames. Add ("Age ");
Columnnames. Add ("Hometown ");
Columnnames. Add ("don't ");
Rowdata = new vector ();
Try {
// Load the driver
// Class. forname ("com. Microsoft. JDBC. sqlserver. sqlserverdriver ");
Class. forname ("com. Microsoft. JDBC. sqlserver. sqlserverdriver ");
System. Out. Print ("DF \ n ");
// Link to start
Ct = drivermanager. getconnection ("JDBC: Microsoft: sqlserver: // 127.0.0.1: 1433;" + "databasename = spdbl", "sa", "SQL ");
PS = CT. preparestatement ("select * from Stu ");
Rsw.ps.exe cutequery ();
While (Rs. Next ())
{
// Rowdata can store multiple rows
Vector hang = new vector ();
Hang. Add (Rs. getstring (1 ));
Hang. Add (Rs. getstring (2 ));
Hang. Add (Rs. getstring (3 ));
Hang. Add (Rs. getint (4 ));
Hang. Add (Rs. getstring (5 ));
Hang. Add (Rs. getstring (6 ));
Rowdata. Add (Hang );
}
} Catch (exception e ){
E. printstacktrace ();
// Todo: handle exception
} Finally {
Try {
Rs. Close ();
PS. Close ();
Ct. Close ();
} Catch (exception E2 ){
E2.printstacktrace ();
// Todo: handle exception
}
}
// Initialize jtable
Jt = new jtable (rowdata, columnnames );
// Initialize JSP
JSP = new jscrollpane (JT );
This. Add (JSP );
This. setsize (300,400 );
This. setdefaclocloseoperation (jframe. exit_on_close );
This. setvisible (true );
}
}