学生信息综合查询管理系统的JAVA编程
导入Java . SQL . *;
导入Java . awt . *;
导入javax . swing . *;
导入Java . awt . event . *;
导入javax . swing . border . *;
导入javax . swing . joptionpane;
类添加扩展面板实现ActionListener{
连接con
语句sql
按钮b1,B2;
TextField tf1,tf2,tf3,tf4,tf5,tf6
Box baseBox,bv1,bv2
Add(){
尝试{
class . forname(" sun . JDBC . odbc . JDBC odbc driver ");
}
catch(ClassNotFoundException e){ }
尝试{
con = driver manager . getconnection(" JDBC:odbc:data ",""," ");
SQL = con . create statement();
}
catch(SQLException ee){}
set layout(new BorderLayout());
Panel p 1 = new Panel();
Panel p2 = new Panel();
TF 1 =新的TextField(16);
tf2 =新文本字段(16);
tf3 =新文本字段(16);
tf4 =新文本字段(16);
tf5 =新文本字段(16);
tf6 =新文本字段(16);
b 1 =新建按钮(" enter ");
b 1 . set background(color . green);
B2 =新按钮(“重置”);
B2 . set background(color . green);
b 1 . addactionlistener(this);
B2 . addactionlistener(this);
p 1 . add(b 1);
p 1 . add(B2);
bv 1 = box . createverticalbox();
Bv1.add(新标签(“学号”));
bv 1 . add(box . createverticalstrut(8));
Bv1.add(新标签("名称"));
bv 1 . add(box . createverticalstrut(8));
Bv1.add(新标签("性别"));
bv 1 . add(box . createverticalstrut(8));
Bv1.add(新标签(“专业”));
bv 1 . add(box . createverticalstrut(8));
Bv1.add(新标签(“等级”));
bv 1 . add(box . createverticalstrut(8));
Bv1.add(新标签(“出生”));
bv 1 . add(box . createverticalstrut(8));
bv2 = box . createverticalbox();
bv2 . add(TF 1);
bv2 . add(box . createverticalstrut(8));
bv2 . add(tf2);
bv2 . add(box . createverticalstrut(8));
bv2 . add(tf3);
bv2 . add(box . createverticalstrut(8));
bv2 . add(tf4);
bv2 . add(box . createverticalstrut(8));
bv2 . add(tf5);
bv2 . add(box . createverticalstrut(8));
bv2 . add(tf6);
bv2 . add(box . createverticalstrut(8));
base box = box . createhorizontalbox();
base box . add(bv 1);
base box . add(box . createhorizontalstrust(10));
base box . add(bv2);
p2 . add(base box);
add(p1,“南”);
add(p2,“居中”);
setSize(350,300);
set background(color . pink);
}
public void action performed(action event e){
if(e.getSource()==b1){
请尝试{ insert();}
catch(SQLException ee){}
Joptionpane。显示消息对话框(这,“数据已被放入存储!”,“提示对话框”,jooptionpane。信息_消息);
}
else if(e.getSource()==b2){
TF 1 . settext(" ");
tf2 . settext(" ");
tf3 . settext(" ");
tf4 . settext(" ");
tf5 . settext(" ");
tf6 . settext(" ");
}
}
public void insert()引发SQLException{
string s 1 = " "+TF 1 . gettext()。trim()+" ' ";
string S2 = " "+tf2 . gettext()。trim()+" ' ";
string S3 = " "+tf3 . gettext()。trim()+" ' ";
string S4 = " "+tf4 . gettext()。trim()+" ' ";
string S5 = " "+tf5 . gettext()。trim()+" ' ";
string S6 = " "+tf6 . gettext()。trim()+" ' ";
string temp = " INSERT INTO Jesse VALUES("+s 1+","+s2+","+s3+","+s4+","+s5+","+S6+");
con = driver manager . getconnection(" JDBC:odbc:data ",""," ");
SQL . execute query(temp);
con . close();
}
}
类查询扩展面板实现ActionListener{
连接con
语句sql
TextField t1,t2,t3,t4,t5,T6;
按钮b;
Box baseBox,bv1,bv2
int flag = 0;
查询(){
尝试{
class . forname(" sun . JDBC . odbc . JDBC odbc driver ");
}
catch(ClassNotFoundException e){ }
尝试{
con = driver manager . getconnection(" JDBC:odbc:data ",""," ");
SQL = con . create statement();
}
catch(SQLException ee){}
set layout(new BorderLayout());
b =新建按钮(“查询”);
b . set background(color . orange);
b . addactionlistener(this);
t 1 = new TextField(8);
t2 =新文本字段(16);
t3 =新文本字段(16);
T4 = new TextField(16);
t5 =新文本字段(16);
t6 =新文本字段(16);
T2 . set editable(false);
T3 . set editable(false);
T4 . set editable(false);
t5 . set editable(false);
T6 . set editable(false);
Panel p1=new Panel(),p2 = new Panel();
P1.add(新标签("输入学号查询"));
p 1 . add(t 1);
p 1 . add(b);
bv 1 = box . createverticalbox();
Bv1.add(新标签("名称"));
bv 1 . add(box . createverticalstrut(8));
Bv1.add(新标签("性别"));
bv 1 . add(box . createverticalstrut(8));
Bv1.add(新标签(“专业”));
bv 1 . add(box . createverticalstrut(8));
Bv1.add(新标签(“等级”));
bv 1 . add(box . createverticalstrut(8));
Bv1.add(新标签(“出生”));
bv 1 . add(box . createverticalstrut(8));
bv2 = box . createverticalbox();
bv2 . add(T2);
bv2 . add(box . createverticalstrut(8));
bv2 . add(T3);
bv2 . add(box . createverticalstrut(8));
bv2 . add(T4);
bv2 . add(box . createverticalstrut(8));
bv2 . add(t5);
bv2 . add(box . createverticalstrut(8));
bv2 . add(T6);
bv2 . add(box . createverticalstrut(8));
base box = box . createhorizontalbox();
base box . add(bv 1);
base box . add(box . createhorizontalstrust(10));
base box . add(bv2);
p2 . add(base box);
add(p1,"北");
add(p2,“居中”);
setSize(300,250);
set background(color . red);
}
public void action performed(action event e){
flag = 0;
请尝试{ query();}
catch(SQLException ee){}
}
公共void查询()引发SQLException{
字符串编号、姓名、性别、科目、年级、出生;
con = driver manager . getconnection(" JDBC:odbc:data ",""," ");
ResultSet RS = SQL . execute query(" SELECT * FROM Jesse ");
while(rs.next()){
Num=rs.getString("学号");
name = RS . getstring(" name ");
sex = RS . getstring(" gender ");
subject = RS . getstring(" major ");
grade = RS . getstring(" grade ");
born = RS . getstring(" born ");
if(num.equals(t1.getText()。trim())){
t2.setText(名称);
t3.setText(性);
t4.setText(主题);
t5.setText(等级);
T6 . settext(born);
flag = 1;
打破;
}
}
con . close();
If(flag==0){t1.setText("无学生");}
}
}
类更新扩展面板实现ActionListener{
连接con
语句sql
按钮b1,b2,B3;
Box baseBox,bv1,bv2
TextField t1,t2,t3,t4,t5,T6;
Update(){
尝试{
class . forname(" sun . JDBC . odbc . JDBC odbc driver ");
}
catch(ClassNotFoundException e){ }
尝试{
con = driver manager . getconnection(" JDBC:odbc:data ",""," ");
SQL = con . create statement();
}
catch(SQLException ee){}
set layout(new BorderLayout());
b 1 =新建按钮("开始修改");
b 1 . set background(color . green);
B2 =新建按钮(“输入修改”);
B2 . set background(color . yellow);
B3 =新按钮(“重置”);
B3 . set background(color . yellow);
b 1 . addactionlistener(this);
B2 . addactionlistener(this);
B3 . addactionlistener(this);
t 1 = new TextField(8);
t2 =新文本字段(16);
t3 =新文本字段(16);
T4 = new TextField(16);
t5 =新文本字段(16);
t6 =新文本字段(16);
Panel p1=new Panel(),p2=new Panel(),P3 = new Panel();
P1.add(新标签("输入要修改信息的学号"));
p 1 . add(t 1);
p 1 . add(b 1);
bv 1 = box . createverticalbox();
Bv1.add(新标签("(新)名"));
bv 1 . add(box . createverticalstrut(8));
Bv1.add(新标签("(新)性别"));
bv 1 . add(box . createverticalstrut(8));
Bv1.add(新标签("(新)专业"));
bv 1 . add(box . createverticalstrut(8));
Bv1.add(新标签("(新)等级"));
bv 1 . add(box . createverticalstrut(8));
Bv1.add(新标签("(新)出生"));
bv 1 . add(box . createverticalstrut(8));
bv2 = box . createverticalbox();
bv2 . add(T2);
bv2 . add(box . createverticalstrut(8));
bv2 . add(T3);
bv2 . add(box . createverticalstrut(8));
bv2 . add(T4);
bv2 . add(box . createverticalstrut(8));
bv2 . add(t5);
bv2 . add(box . createverticalstrut(8));
bv2 . add(T6);
bv2 . add(box . createverticalstrut(8));
base box = box . createhorizontalbox();
base box . add(bv 1);
base box . add(box . createhorizontalstrust(10));
base box . add(bv2);
p2 . add(base box);
P3 . add(B2);
P3 . add(B3);
add(p1,"北");
add(p2,“居中”);
添加(p3,“南”);
setSize(300,250);
set background(color . cyan);
}
public void action performed(action event e){
if(e.getSource()==b1){
尝试{
字符串编号、姓名、性别、科目、年级、出生;
con = driver manager . getconnection(" JDBC:odbc:data ",""," ");
ResultSet RS = SQL . execute query(" SELECT * FROM Jesse ");
while(rs.next()){
Num=rs.getString("学号");
name = RS . getstring(" name ");
sex = RS . getstring(" gender ");
subject = RS . getstring(" major ");
grade = RS . getstring(" grade ");
born = RS . getstring(" born ");
if(num.equals(t1.getText()。trim())){
t2.setText(名称);
t3.setText(性);
t4.setText(主题);
t5.setText(等级);
T6 . settext(born);
打破;
}
}
con . close();
}
catch(SQLException ee){}
}
if(e.getSource()==b2){
请尝试{ update();}
catch(SQLException ee){}
}
if(e.getSource()==b3){
T2 . settext(" ");
T3 . settext(" ");
T4 . settext(" ");
t5 . settext(" ");
T6 . settext(" ");
}
}
public void update()引发SQLException{
string s 1 = " "+t 1 . gettext()。trim()+" ' ";
string S2 = " "+T2 . gettext()。trim()+" ' ";
string S3 = " "+T3 . gettext()。trim()+" ' ";
string S4 = " "+T4 . gettext()。trim()+" ' ";
string S5 = " "+t5 . gettext()。trim()+" ' ";
string S6 = " "+T6 . gettext()。trim()+" ' ";
string temp = " UPDATE Jesse SET Name = "+S2+"、Gender ="+s3+"、Major ="+s4+"、Grade ="+s5+"、Birth ="+s6+"其中学号= "+s 1;
con = driver manager . getconnection(" JDBC:odbc:data ",""," ");
SQL . execute query(temp);
con . close();
}
}
类删除扩展面板实现ActionListener{
连接con
语句sql
TextField t1,t2,t3,t4,t5,T6;
按钮b;
Box baseBox,bv1,bv2
Delete(){
尝试{
class . forname(" sun . JDBC . odbc . JDBC odbc driver ");
}
catch(ClassNotFoundException e){ }
尝试{
con = driver manager . getconnection(" JDBC:odbc:data ",""," ");
SQL = con . create statement();
}
catch(SQLException ee){}
set layout(new BorderLayout());
b =新建按钮(“删除”);
b . set background(color . cyan);
b . addactionlistener(this);
t 1 = new TextField(8);
t 1 . addactionlistener(this);
t2 =新文本字段(16);
t3 =新文本字段(16);
T4 = new TextField(16);
t5 =新文本字段(16);
t6 =新文本字段(16);
T2 . set editable(false);
T3 . set editable(false);
T4 . set editable(false);
t5 . set editable(false);
T6 . set editable(false);
Panel p1=new Panel(),p2 = new Panel();
P1.add(新标签("输入学号删除"));
p 1 . add(t 1);
p 1 . add(b);
bv 1 = box . createverticalbox();
Bv1.add(新标签("名称"));
bv 1 . add(box . createverticalstrut(8));
Bv1.add(新标签("性别"));
bv 1 . add(box . createverticalstrut(8));
Bv1.add(新标签(“专业”));
bv 1 . add(box . createverticalstrut(8));
Bv1.add(新标签(“等级”));
bv 1 . add(box . createverticalstrut(8));
Bv1.add(新标签(“出生”));
bv 1 . add(box . createverticalstrut(8));
bv2 = box . createverticalbox();
bv2 . add(T2);
bv2 . add(box . createverticalstrut(8));
bv2 . add(T3);
bv2 . add(box . createverticalstrut(8));
bv2 . add(T4);
bv2 . add(box . createverticalstrut(8));
bv2 . add(t5);
bv2 . add(box . createverticalstrut(8));
bv2 . add(T6);
bv2 . add(box . createverticalstrut(8));
base box = box . createhorizontalbox();
base box . add(bv 1);
base box . add(box . createhorizontalstrust(10));
base box . add(bv2);
p2 . add(base box);
add(p1,"北");
add(p2,“居中”);
setSize(300,250);
set background(color . green);
}
public void action performed(action event e){
if(e.getSource()==t1){
请尝试{ delete();}
catch(SQLException ee){}
}
else if(e.getSource()==b){
Int n = Joption窗格。ShowConfirmDiarog (this,“你确定要删除这个学号和所有信息吗?”,“OK”,JOptionPane。YES _ NO _ OPTION);
if(n==JOptionPane。是_选项){
尝试{
string s 1 = " "+t 1 . gettext()。trim()+" ' ";
string temp = " delete from Jesse where student number = "+s 1;
con = driver manager . getconnection(" JDBC:odbc:data ",""," ");
SQL . execute update(temp);
con . close();
}
catch(SQLException ee){}
}
else if(n==JOptionPane。NO_OPTION){}
}
}
public void delete()引发SQLException{
字符串编号、姓名、性别、科目、年级、出生;
con = driver manager . getconnection(" JDBC:odbc:data ",""," ");
ResultSet RS = SQL . execute query(" SELECT * FROM Jesse ");
while(rs.next()){
Num=rs.getString("学号");
name = RS . getstring(" name ");
sex = RS . getstring(" gender ");
subject = RS . getstring(" major ");
grade = RS . getstring(" grade ");
born = RS . getstring(" born ");
if(num.equals(t1.getText()。trim())){
t2.setText(名称);
t3.setText(性);
t4.setText(主题);
t5.setText(等级);
T6 . settext(born);
打破;
}
}
con . close();
}
}
公共类tyj扩展框架实现ActionListener{
菜单栏= null
菜单menu1,menu2,menu3,menu4,menu5
MenuItem item1,item2,item3,item4,item5。
加曾家;
查询查迅;
更新庚欣;
删除山初;
tyj(){
Super("欢迎使用学生信息管理系统");
曾家= new Add();
cha Xun = new Query();
庚欣=新更新();
shanchu = new Delete();
bar = new MenuBar();
Menu 1 =新菜单(“信息输入”);
Menu2 =新建菜单(“信息查询”);
Menu3 =新菜单(“信息更新”);
Menu4 =新菜单(“信息删除”);
Menu5 =新菜单(“退出系统”);
item 1 = new MenuItem(" entry ");
item 2 = new MenuItem(" query ");
item 3 = new MenuItem(" update ");
item 4 = new MenuItem(" delete ");
item 5 = new MenuItem(" exit ");
menu 1 . add(item 1);
menu 2 . add(item 2);
menu 3 . add(item 3);
menu 4 . add(item 4);
menu 5 . add(item 5);
bar . add(menu 1);
bar . add(menu 2);
bar . add(menu 3);
bar . add(menu 4);
bar . add(menu 5);
setMenuBar(条);
item 1 . addactionlistener(this);
item 2 . addactionlistener(this);
item 3 . addactionlistener(this);
item 4 . addactionlistener(this);
item 5 . addactionlistener(this);
Label label =新标签(“欢迎使用学生信息管理系统”,标签。中心);
字符串s =
字体f =新字体(s,字体。粗体,22);
label . set font(f);
label.setBackground(颜色。绿色);
label.setForeground(Color。蓝色);
添加(标签,“居中”);
set visible(true);
setSize(320,300);
}
public void action performed(action event e){
if(e . getsource()= = item 1){
remove all();
add(曾家,“中心”);
validate();
}
if(e.getSource()==item2){
remove all();
加(查勋,“中心”);
validate();
}
if(e.getSource()==item3){
remove all();
加(庚欣,“居中”);
validate();
}
if(e.getSource()==item4){
remove all();
添加(山初,“中心”);
validate();
}
if(e.getSource()==item5){
remove all();
setBackground(颜色。绿色);
Label label =新标签(“欢迎使用学生信息管理系统”,标签。中心);
字符串s =
字体f =新字体(s,字体。粗体,22);
label . set font(f);
label.setForeground(Color。蓝色);
添加(标签,“居中”);
validate();
}
}
公共静态void main(String[] args)
{
tyj Jesse = new tyj();
Jesse . set visible(true);
Jesse . addwindowlistener(new window adapter(){
public void window closing(window event e){
system . exit(0);
}
});
}
}