/*这是一个简单的学生信息管理系统,其中我使用了数据库Access,可是界面能够运行出来,但里面的功能却不能用,可能是数据库那块弄得不好,不过驱动设置没错。我改了好久也没改出来。不知道哪里出错,想请高手指点一下,代码如下。*/
import java.awt.*;
import java.applet.Applet;
import java.sql.*;
import java.awt.event.*;
public class student_manage extends Applet implements ActionListener //,ImageListener
{
Label pro1,pro2,pro3,pro4,pro5,pro6,pro7;
TextField input1,input2,input3,input4,input5;
Button btn1,btn2,btn3,btn4;
Choice mw;
public void init()
{
setLayout(new GridLayout(10,3));
pro1=new Label("学生信息管理系统");
pro2=new Label("管理员账号");
pro3=new Label("管理员密码");
btn1=new Button("登陆");
input1=new TextField(8);
input2=new TextField(8);
pro4=new Label(" 性别"); mw=new Choice();mw.add("男");mw.add("女");
pro5=new Label(" 班级"); input3=new TextField(8);
pro6=new Label(" 成绩1"); input4=new TextField(8);
pro7=new Label(" 成绩2"); input5=new TextField(8);
btn2=new Button("查询");
btn3=new Button("保存");
btn4=new Button("删除");
add(new Label()); add(pro1); add(new Label());
add(pro2); add(input1); add(new Label());
add(pro3); add(input2); add(btn1);
add(pro4); add(mw); add(new Label());
add(pro5); add(input3); add(new Label());
add(pro6); add(input4); add(new Label());
add(pro7); add(input5); add(new Label());
add(btn2); add(btn3); add(btn4);
btn1.addActionListener(this);
btn2.addActionListener(this);
btn3.addActionListener(this);
btn4.addActionListener(this);
pro4.setVisible(false);mw.setVisible(false);
pro5.setVisible(false);input3.setVisible(false);
pro6.setVisible(false);input4.setVisible(false);
pro7.setVisible(false);input5.setVisible(false);
btn2.setVisible(false);btn3.setVisible(false);
btn4.setVisible(false);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==btn1)
{
String zh,mm;
zh=input1.getText();
mm=input2.getText();
if(zh.equals("a")==true&&mm.equals("123")==true)
{
pro1.setText("学生信息");
pro2.setText(" 学号");
pro3.setText(" 姓名");
input1.setText("");
input2.setText("");
pro4.setVisible(true);mw.setVisible(true);btn1.setVisible(false);
pro5.setVisible(true);input3.setVisible(true);
pro6.setVisible(true);input4.setVisible(true);
pro7.setVisible(true);input5.setVisible(true);
btn2.setVisible(true);btn3.setVisible(true);
btn4.setVisible(true);
}
}
if(e.getActionCommand()=="查询")
{
String noa;
noa=input1.getText();
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(Exception E)
{
E.printStackTrace();
}
try
{
Connection con=DriverManager.getConnection("jdbc:odbc:ld","Admin","");
Statement stmt=con.createStatement();
ResultSet rs;
rs=stmt.executeQuery("SELECT Sname,Ssex,Sclas,Sresult1,Sresult2 FROM ld WHERE (Sno="+noa+")");
while(rs.next())
{
input2.setText(rs.getString(1));
mw.select(rs.getString(2));
input3.setText(rs.getString(3));
input4.setText(rs.getString(4));
input5.setText(rs.getString(5));
}
con.close();
}
catch(Exception E)
{
E.printStackTrace();
}
}
if(e.getActionCommand()=="保存")
{
String noa;
String namea;
String sexa;
String clasa;
int result1a;
int result1b;
noa="'"+input1.getText()+"'";
namea="'"+input1.getText()+"'";
sexa="'"+mw.getSelectedItem()+"'";
clasa="'"+input1.getText()+"'";
result1a=Integer.parseInt(input1.getText());
result1b=Integer.parseInt(input1.getText());
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(Exception E)
{
E.printStackTrace();
}
try
{
Connection con=DriverManager.getConnection("jdbc:odbc:ld","Admin","");
Statement stmt=con.createStatement();
stmt.executeUpdate(" INSERT INTO ld VALUES ("+noa+","+namea+","+sexa+","+clasa+",'result1a','result1b')");
con.close();
}
catch(Exception E)
{
E.printStackTrace();
}
input1.setText("");
input2.setText("");
input3.setText("");
input4.setText("");
input5.setText("");
}
if(e.getActionCommand()=="删除")
{
String noa;
noa="'"+input1.getText()+"'";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(Exception E)
{
E.printStackTrace();
}
try
{
Connection con=DriverManager.getConnection("jdbc:odbc:ld","Admin","");
Statement stmt=con.createStatement();
stmt.executeUpdate("DELETE FROM ld WHERE Sno="+noa+"");
con.close();
}
catch(Exception E)
{
E.printStackTrace();
}
input1.setText("");
input2.setText("");
input3.setText("");
input4.setText("");
input5.setText("");
}
}
}