学生信息查询java代码 学生信息查询java代码是什么

求一个用java写的学生成绩管理信息系统的源代码,要求有界面,能实现以下方法实现了用户界面登陆
import java.awt.*;
import java.awt.event.*;
public class DengLuJieMian extends Frame implements ActionListener
{
Label username=new Label("用户名:");//使用文本创建一个用户名标签
TextField t1=new TextField();//创建一个文本框对象
Label password=new Label("密码:");//创建一个密码标签
TextField t2=new TextField();
Button b1=new Button("登陆");//创建登陆按钮
Button b2=new Button("取消");//创建取消按钮
public DengLuJieMian()
{
this.setTitle("学生信息管理系统");//设置窗口标题
this.setLayout(null);//设置窗口布局管理器
username.setBounds(50,40,60,20);//设置姓名标签的初始位置
this.add(username);// 将姓名标签组件添加到容器
t1.setBounds(120,40,80,20);// 设置文本框的初始位置
this.add(t1);// 将文本框组件添加到容器
password.setBounds(50,100,60,20);//密码标签的初始位置
this.add(password);//将密码标签组件添加到容器
t2.setBounds(120,100,80,20);//设置密码标签的初始位置
this.add(t2);//将密码标签组件添加到容器
b1.setBounds(50,150,60,20);//设置登陆按钮的初始位置
this.add(b1);//将登陆按钮组件添加到容器
b2.setBounds(120,150,60,20);//设置取消按钮的初始位置
this.add(b2);// 将取消按钮组件添加到容器
b1.addActionListener(this);//给登陆按钮添加监听器
b2.addActionListener(this);// 给取消按钮添加监听器
this.setVisible(true);//设置窗口的可见性
this.setSize(300,200);//设置窗口的大小
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});//通过内部类重写关闭窗体的方法
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)//处理登陆事件
{
String name=t1.getText();
String pass=t2.getText();
if(name!=nullpass.equals("000123"))//判断语句
{
new StudentJieMian();
}
}
}
public static void main(String args[])//主函数
{
new DengLuJieMian();
}
}
以下方法实现了学生界面设计
import java.awt.*;
import java.awt.event.*;
class StudentJieMian extends Frame implements ActionListener
{
MenuBar m=new MenuBar();//创建菜单栏
Menu m1=new Menu("信息");//创建菜单“信息”
MenuItem m11=new MenuItem("插入");//创建“插入”的菜单项
MenuItem m12=new MenuItem("查询");
Menu m2=new Menu("成绩");//创建菜单“成绩”
MenuItem m21=new MenuItem("查询");
public StudentJieMian()
{
this.setTitle("学生界面");//设置窗口标题
this.setLayout(new CardLayout());//设置窗口布局管理器
this.setMenuBar(m);//将菜单栏组件添加到容器
m.add(m1);//将信息菜单放入菜单栏
m.add(m2);
m1.add(m11);//将“插入”菜单项添加到“信息”菜单
m1.add(m12); //将“查询”菜单项添加到“信息”菜单
m2.add(m21); //将“查询”菜单项添加到“成绩”菜单
m11.addActionListener(this); //给“插入”菜单项添加监听器
m12.addActionListener(this); //给“查询”菜单项添加监听器
m21.addActionListener(this); //给“查询”菜单项添加监听器
this.setVisible(true); //设置窗口的可见性
this.setSize(300,200); //设置窗口的大小
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);//关闭窗口
}
});
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==m11)//处理“添加信息”事件
{
new AddStudent();
}
if(e.getSource()==m12)//处理“查询信息”事件
{
new SelectStudent();
}
if(e.getSource()==m21)//处理“查询成绩”事件
{
new ChengJiStudent();
}
}
public static void main(String args[])
{new StudentJieMian();//创建一个对象}
用JAVA list集合语句增删改查全部学生信息 。1、首先在电脑上启动数据库,在数据库中创建表,下面给出具体的SQL语句 。
2、然后打开eclipse 创建新项目 JDBCTest,需要导入相关的jar包并构建路径,如图 。
3、接着创建entity实体层如图对应表中的数据 。
4、创建数据连接层conn 用于MySQL数据库的连接代码如图 如图 。
5、创建dao层持久层 , 在里面编写数据库表的增删改查的具体操作 。
6、最后编写测试类 Test代码如图,就完成了 。
.给出存储班级三十名学生基本信息的Java代码 , 基本信息的具体赋值由考生自拟?下面是一个存储班级三十名学生基本信息的 Java 代码示例:
import java.util.ArrayList;
public class Student {
private String name;
private int age;
private String gender;
public Student(String name, int age, String gender) {
this.name = name;
this.age = age;
this.gender = gender;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
public String getGender() {
return gender;
}
}
public class Classroom {
private ArrayListStudent students;
public Classroom() {
this.students = new ArrayListStudent();
}
public void addStudent(Student student) {
students.add(student);
}
public ArrayListStudent getStudents() {
return students;
}
}
public class Main {
public static void main(String[] args) {
Classroom classroom = new Classroom();
// 添加 30 名学生的基本信息
classroom.addStudent(new Student("Tom", 18, "Male"));
classroom.addStudent(new Student("Alice", 19, "Female"));
// ...
// 此处省略 28 名学生的信息
// 获取所有学生的信息
ArrayListStudent students = classroom.getStudents();
for (Student student : students) {
System.out.println("Name: "student.getName());
System.out.println("Age: "student.getAge());
System.out.println("Gender: "student.getGender());
}
}
}
该代码定义了两个类:Student 类表示一个学生,包含了学生的姓名、年龄和性别等信息;Classroom 类表示一个班级,包含了一个学生的列表 , 并提供了添加学生和获取学生列表的方法 。
在 Main 类的 main 方法中 , 我们首先实例化一个 Classroom 对象 , 然后依次添加 30 名学生的信息 。最后,我们调用 getStudents 方法获取所
急求java学生信息管理系统源代码,带有连接数据库的,万分感谢import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import javax.swing.SwingConstants;
public class MainFrame extends JFrame implements ActionListener{
InsertPanel ip = null;
SelectPanel sp = null;
JPanel pframe;
JButton jb1,jb2,jb3;
JMenuItem jm11,jm21,jm22,jm23,jm31,jm32,jm41,jm42;
CardLayout clayout;
public MainFrame(String s){
super(s);
JMenuBar mb = new JMenuBar();
this.setJMenuBar(mb);
JMenu m1 = new JMenu("系统");
JMenu m2 = new JMenu("基本信息");
JMenu m3 = new JMenu("成绩");
JMenu m4 = new JMenu("奖惩");
mb.add(m1);
mb.add(m2);
mb.add(m3);
mb.add(m4);
jm11 = new JMenuItem("退出系统");
jm21 = new JMenuItem("输入");
jm22 = new JMenuItem("查询");
jm23 = new JMenuItem("更改");
jm31 = new JMenuItem("输入成绩");
jm32 = new JMenuItem("查询成绩");
jm41 = new JMenuItem("奖励");
jm42 = new JMenuItem("处分");
m1.add(jm11);
m2.add(jm21);
m2.add(jm22);
m2.add(jm23);
m3.add(jm31);
m3.add(jm32);
m4.add(jm41);
m4.add(jm42);
Icon i1 = new ImageIcon();
Icon i2 = new ImageIcon();
Icon i3 = new ImageIcon();
jb1 = new JButton(i1);
jb1.setToolTipText("输入");
jb2 = new JButton(i2);
jb2.setToolTipText("查询");
jb3 = new JButton(i3);
jb3.setToolTipText("退出");
JToolBar tb = new JToolBar("系统工具");
tb.add(jb1);
tb.add(jb2);
tb.add(jb3);
add(tb,BorderLayout.NORTH);
jm11.addActionListener(this);
jm21.addActionListener(this);
jm22.addActionListener(this);
jb1.addActionListener(this);
jb2.addActionListener(this);
jb3.addActionListener(this);
clayout = new CardLayout();
pframe = new JPanel(clayout);
add(pframe);
JPanel mainp = new JPanel(new BorderLayout());
JLabel mainl = new JLabel("学生信息管理平台",SwingConstants.CENTER);
mainl.setFont(new Font("serif",Font.BOLD,30));
mainp.add(mainl);
pframe.add(mainp,"main");
clayout.show(pframe, "main");
}
public void actionPerformed(ActionEvent e){
if(e.getSource() == jm21 || e.getSource() == jb1){
if(ip == null){
ip= new InsertPanel();
pframe.add(ip,"insert");
}
clayout.show(pframe, "insert");
this.setTitle("输入学生信息");
}
else if(e.getSource() == jm22 || e.getSource() == jb2){
if(sp == null){
sp= new SelectPanel();
pframe.add(sp,"select");
}
clayout.show(pframe, "select");
this.setTitle("查询学生信息");
}
else if(e.getSource() == jm11 || e.getSource() == jb3){
System.exit(0);
}
}
}
第二个:
import javax.swing.JFrame;
public class MainTest {
public static void main(String [] args){
MainFrame f = new MainFrame("学生信息管理平台");
f.setSize(400,300);
f.setLocation(350,250);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
第二个:
import java.sql.Connection;
import java.sql.DriverManager;
public class MySQLConnection {
static Connection getCon(){
Connection con = null;
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/test","root","123");
}
catch(Exception e){
System.out.println("建立数据库连接遇到异常!");
}
return con;
}
}
第四个:
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
【学生信息查询java代码 学生信息查询java代码是什么】import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
public class SelectPanel extends JPanel implements ActionListener{
JButton jb;
JTextField jt;
JTextField jt1,jt2,jt3,jt4;
public SelectPanel(){
JLabel jl = new JLabel("请输入学号:",SwingConstants.CENTER);
jt= new JTextField();
jb = new JButton("确定");
JPanel jp1 = new JPanel(new GridLayout(1,3));
jp1.add(jl);
jp1.add(jt);
jp1.add(jb);
JLabel j1,j2,j3,j4;
j1 = new JLabel("学号:",SwingConstants.CENTER);
j2 = new JLabel("姓名:",SwingConstants.CENTER);
j3 = new JLabel("性别:",SwingConstants.CENTER);
j4 = new JLabel("年龄:",SwingConstants.CENTER);
jt1 = new JTextField(6);
jt1.setEditable(false);
jt2 = new JTextField(6);
jt2.setEditable(false);
jt3 = new JTextField(6);
jt3.setEditable(false);
jt4 = new JTextField(6);
jt4.setEditable(false);
JPanel jp2 = new JPanel(new BorderLayout());
JPanel jp3 = new JPanel(new GridLayout(4,2));
jp2.add(new JLabel(""),BorderLayout.NORTH);
jp3.add(j1);
jp3.add(jt1);
jp3.add(j2);
jp3.add(jt2);
jp3.add(j3);
jp3.add(jt3);
jp3.add(j4);
jp3.add(jt4);
jp2.add(jp3);
this.setLayout(new BorderLayout());
add(jp1,BorderLayout.NORTH);
add(jp2);
jb.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if(e.getSource() == jb){
String stuNo = jt.getText().trim();
Student s = new Student();
boolean b = true;
try{
b = s.selectByStuNo(stuNo);
}
catch(Exception ex){
System.out.println("查询学生信息遇到异常!");
}
if(b){
jt1.setText(s.getStuNo());
jt2.setText(s.getName());
jt3.setText(s.getGender());
int a = s.getAge();
Integer i = new Integer(a);
jt4.setText(i.toString());
}
else{
JOptionPane.showMessageDialog(null, "无此学生!");
}
}
}
}
第五个:
import javax.swing.JFrame;
public class SelectTest {
public static void main(String [] args){
JFrame f = new JFrame("查询学生信息");
SelectPanel p = new SelectPanel();
f.add(p);
f.setSize(400,300);
f.setLocation(300,250);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
第六个:
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
public class Student {
String stuNo;
String name;
String gender;
int age;
public Student(){}
public Student(String stuNo,String name,String gender, int age){
this.stuNo = stuNo;
this.name = name;
this.gender = gender;
this.age = age;
}
public String getStuNo(){
return stuNo;
}
public void setStuNo(String stuNo){
this.stuNo = stuNo;
}
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
public String getGender(){
return gender;
}
public void setGender(String gender){
this.gender = gender;
}
public int getAge(){
return age;
}
public void setAge(int age){
this.age = age;
}
public boolean insertStudent(){
boolean b = true;
try{
Connection con = MySQLConnection.getCon();
Statement statement = con.createStatement();
String sql = "insert into student values('"stuNo"','"name"','"gender"',"age")";
sql = new String(sql.getBytes("gb2312"),"ISO8859_1");
statement.executeUpdate(sql);
con.close();
}
catch(Exception e){
b = false;
System.out.println("插入数据库遇到异常!");
}
return b;
}
public boolean selectByStuNo(String stuNo)throws Exception{
boolean b = true;
Connection con = MySQLConnection.getCon();
Statement statement = con.createStatement();
String sql = "select * from student where stuNo ="stuNo;
ResultSet rs = statement.executeQuery(sql);
if(rs != nullrs.next()){
String no = rs.getString(1);
this.setStuNo(no);
String n = rs.getString(2);
n = new String(n.getBytes("ISO8859_1"),"gb2312");
this.setName(n);
String g = rs.getString(3);
g = new String (g.getBytes("ISO8859_1"),"gb2312");
this.setGender(g);
this.setAge(rs.getInt(4));
b = true;
}
rs.close();
statement.close();
con.close();
return b;
}
}
数据库你自己弄吧,我没时间弄了!初学得多动手哦
java中实现在控制平台上实现学生信息输入、输出、查找、修改,重点是修改?。?/h2>代码如下,有问题请追问:
import java.util.Scanner;
public class InputTest {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String val = null;// 记录输入的字符串
do{
System.out.print("请输入:");
val = input.next();// 等待输入值
System.out.println("您输入的是:" val);
}while(!val.equals("#"));// 如果输入的值不是#就继续输入
System.out.println("你输入了\"#\",程序已经退出!");
input.close(); // 关闭资源
}
}
学生信息综合查询管理系统JAVA程序编写package test;
import java.sql.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.border.*;
import javax.swing.JOptionPane;
class Add extends Panel implements ActionListener{
Connection con;
Statement sql;
Button b1,b2;
TextField tf1,tf2,tf3,tf4,tf5,tf6;
Box baseBox,bv1,bv2;
Add(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){}
try{
con=DriverManager.getConnection("jdbc:odbc:data","","");
sql=con.createStatement();
}
catch(SQLException ee){}
setLayout(new BorderLayout());
Panel p1=new Panel();
Panel p2=new Panel();
tf1=new TextField(16);
tf2=new TextField(16);
tf3=new TextField(16);
tf4=new TextField(16);
tf5=new TextField(16);
tf6=new TextField(16);
b1=new Button("录入");
b1.setBackground(Color.green);
b2=new Button("重置");
b2.setBackground(Color.green);
b1.addActionListener(this);
b2.addActionListener(this);
p1.add(b1);
p1.add(b2);
bv1=Box.createVerticalBox();
bv1.add(new Label("学号"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("姓名"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("性别"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("专业"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("年级"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("出生"));
bv1.add(Box.createVerticalStrut(8));
bv2=Box.createVerticalBox();
bv2.add(tf1);
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));
baseBox=Box.createHorizontalBox();
baseBox.add(bv1);
baseBox.add(Box.createHorizontalStrut(10));
baseBox.add(bv2);
p2.add(baseBox);
add(p1,"South");
add(p2,"Center");
setSize(350,300);
setBackground(Color.pink);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==b1){
try{ insert();}
catch(SQLException ee){}
JOptionPane.showMessageDialog(this,"数据已入库!","提示对话框",JOptionPane.INFORMATION_MESSAGE);
}
else if(e.getSource()==b2){
tf1.setText(" ");
tf2.setText(" ");
tf3.setText(" ");
tf4.setText(" ");
tf5.setText(" ");
tf6.setText(" ");
}
}
public void insert() throws SQLException{
String s1="'" tf1.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 (" s1 "," s2 "," s3 "," s4 "," s5 "," s6 ")";
con=DriverManager.getConnection("jdbc:odbc:data","","");
sql.executeQuery(temp);
con.close();
}
}
class Query extends Panel implements ActionListener{
Connection con;
Statement sql;
TextField t1,t2,t3,t4,t5,t6;
Button b;
Box baseBox,bv1,bv2;
int flag=0;
Query(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){}
try{
con=DriverManager.getConnection("jdbc:odbc:data","","");
sql=con.createStatement();
}
catch(SQLException ee){}
setLayout(new BorderLayout());
b=new Button("查询");
b.setBackground(Color.orange);
b.addActionListener(this);
t1=new TextField(8);
t2=new TextField(16);
t3=new TextField(16);
t4=new TextField(16);
t5=new TextField(16);
t6=new TextField(16);
t2.setEditable(false);
t3.setEditable(false);
t4.setEditable(false);
t5.setEditable(false);
t6.setEditable(false);
Panel p1=new Panel(),p2=new Panel();
p1.add(new Label("输入要查询的学号"));
p1.add(t1);
p1.add(b);
bv1=Box.createVerticalBox();
bv1.add(new Label("姓名"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("性别"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("专业"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("年级"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("出生"));
bv1.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));
baseBox=Box.createHorizontalBox();
baseBox.add(bv1);
baseBox.add(Box.createHorizontalStrut(10));
baseBox.add(bv2);
p2.add(baseBox);
add(p1,"North");
add(p2,"Center");
setSize(300,250);
setBackground(Color.red);
}
public void actionPerformed(ActionEvent e){
flag=0;
try{query();}
catch(SQLException ee){}
}
public void query() throws SQLException{
String num,name,sex,subject,grade,born;
con=DriverManager.getConnection("jdbc:odbc:data","","");
ResultSet rs=sql.executeQuery("SELECT * FROM jesse ");
while(rs.next()){
num=rs.getString("学号");
name=rs.getString("姓名");
sex=rs.getString("性别");
subject=rs.getString("专业");
grade=rs.getString("年级");
born=rs.getString("出生");
if(num.equals(t1.getText().trim())){
t2.setText(name);
t3.setText(sex);
t4.setText(subject);
t5.setText(grade);
t6.setText(born);
flag=1;
break;
}
}
con.close();
if(flag==0){t1.setText("没有该学生");}
}
}
class Update extends Panel implements ActionListener{
Connection con;
Statement sql;
Button b1,b2,b3;
Box baseBox,bv1,bv2;
TextField t1,t2,t3,t4,t5,t6;
Update(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){}
try{
con=DriverManager.getConnection("jdbc:odbc:data","","");
sql=con.createStatement();
}
catch(SQLException ee){}
setLayout(new BorderLayout());
b1=new Button("开始修改");
b1.setBackground(Color.green);
b2=new Button("录入修改");
b2.setBackground(Color.yellow);
b3=new Button("重置");
b3.setBackground(Color.yellow);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
t1=new TextField(8);
t2=new TextField(16);
t3=new TextField(16);
t4=new TextField(16);
t5=new TextField(16);
t6=new TextField(16);
Panel p1=new Panel(),p2=new Panel(),p3=new Panel();
p1.add(new Label("输入要修改信息的学号"));
p1.add(t1);
p1.add(b1);
bv1=Box.createVerticalBox();
bv1.add(new Label("(新)姓名"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("(新)性别"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("(新)专业"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("(新)年级"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("(新)出生"));
bv1.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));
baseBox=Box.createHorizontalBox();
baseBox.add(bv1);
baseBox.add(Box.createHorizontalStrut(10));
baseBox.add(bv2);
p2.add(baseBox);
p3.add(b2);
p3.add(b3);
add(p1,"North");
add(p2,"Center");
add(p3,"South");
setSize(300,250);
setBackground(Color.cyan);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==b1){
try{
String num,name,sex,subject,grade,born;
con=DriverManager.getConnection("jdbc:odbc:data","","");
ResultSet rs=sql.executeQuery("SELECT * FROM jesse ");
while(rs.next()){
num=rs.getString("学号");
name=rs.getString("姓名");
sex=rs.getString("性别");
subject=rs.getString("专业");
grade=rs.getString("年级");
born=rs.getString("出生");
if(num.equals(t1.getText().trim())){
t2.setText(name);
t3.setText(sex);
t4.setText(subject);
t5.setText(grade);
t6.setText(born);
break;
}
}
con.close();
}
catch(SQLException ee){}
}
if(e.getSource()==b2){
try{update();}
catch(SQLException ee){}
}
if(e.getSource()==b3){
t2.setText(" ");
t3.setText(" ");
t4.setText(" ");
t5.setText(" ");
t6.setText(" ");
}
}
public void update() throws SQLException{
String s1="'" t1.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 姓名 =" s2 ", 性别=" s3 ", 专业=" s4 ", 年级=" s5 ", 出生=" s6 " WHERE 学号=" s1;
con=DriverManager.getConnection("jdbc:odbc:data","","");
sql.executeQuery(temp);
con.close();
}
}
class Delete extends Panel implements ActionListener{
Connection con;
Statement sql;
TextField t1,t2,t3,t4,t5,t6;
Button b;
Box baseBox,bv1,bv2;
Delete(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){}
try{
con=DriverManager.getConnection("jdbc:odbc:data","","");
sql=con.createStatement();
}
catch(SQLException ee){}
setLayout(new BorderLayout());
b=new Button("删除");
b.setBackground(Color.cyan);
b.addActionListener(this);
t1=new TextField(8);
t1.addActionListener(this);
t2=new TextField(16);
t3=new TextField(16);
t4=new TextField(16);
t5=new TextField(16);
t6=new TextField(16);
t2.setEditable(false);
t3.setEditable(false);
t4.setEditable(false);
t5.setEditable(false);
t6.setEditable(false);
Panel p1=new Panel(),p2=new Panel();
p1.add(new Label("输入要删除的学号"));
p1.add(t1);
p1.add(b);
bv1=Box.createVerticalBox();
bv1.add(new Label("姓名"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("性别"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("专业"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("年级"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("出生"));
bv1.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));
baseBox=Box.createHorizontalBox();
baseBox.add(bv1);
baseBox.add(Box.createHorizontalStrut(10));
baseBox.add(bv2);
p2.add(baseBox);
add(p1,"North");
add(p2,"Center");
setSize(300,250);
setBackground(Color.green);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==t1){
try{delete();}
catch(SQLException ee){}
}
else if(e.getSource()==b){
int n=JOptionPane.showConfirmDialog(this,"确定要删除该学号及全部信息吗?","确定",JOptionPane.YES_NO_OPTION);
if(n==JOptionPane.YES_OPTION){
try{
String s1="'" t1.getText().trim() "'";
String temp="DELETE FROM jesse WHERE 学号=" s1;
con=DriverManager.getConnection("jdbc:odbc:data","","");
sql.executeUpdate(temp);
con.close();
}
catch(SQLException ee){}
}
else if(n==JOptionPane.NO_OPTION){}
}
}
public void delete() throws SQLException{
String num,name,sex,subject,grade,born;
con=DriverManager.getConnection("jdbc:odbc:data","","");
ResultSet rs=sql.executeQuery("SELECT * FROM jesse ");
while(rs.next()){
num=rs.getString("学号");
name=rs.getString("姓名");
sex=rs.getString("性别");
subject=rs.getString("专业");
grade=rs.getString("年级");
born=rs.getString("出生");
if(num.equals(t1.getText().trim())){
t2.setText(name);
t3.setText(sex);
t4.setText(subject);
t5.setText(grade);
t6.setText(born);
break;
}
}
con.close();
}
}
public class tyj extends Frame implements ActionListener{
MenuBar bar=null;
Menu menu1,menu2,menu3,menu4,menu5;
MenuItem item1,item2,item3,item4,item5;
Add zengjia;
Query chaxun;
Update gengxin;
Delete shanchu;
tyj(){
super("欢迎进入学生信息管理系统");
zengjia=new Add();
chaxun=new Query();
gengxin=new Update();
shanchu=new Delete();
bar=new MenuBar();
menu1=new Menu("信息录入");
menu2=new Menu("信息查询");
menu3=new Menu("信息更新");
menu4=new Menu("信息删除");
menu5=new Menu("退出系统");
item1=new MenuItem("录入");
item2=new MenuItem("查询");
item3=new MenuItem("更新");
item4=new MenuItem("删除");
item5=new MenuItem("退出");
menu1.add(item1);
menu2.add(item2);
menu3.add(item3);
menu4.add(item4);
menu5.add(item5);
bar.add(menu1);
bar.add(menu2);
bar.add(menu3);
bar.add(menu4);
bar.add(menu5);
setMenuBar(bar);
item1.addActionListener(this);
item2.addActionListener(this);
item3.addActionListener(this);
item4.addActionListener(this);
item5.addActionListener(this);
Label label=new Label("欢迎进入学生信息管理系统",Label.CENTER);
String s=" ";
Font f=new Font(s,Font.BOLD,22);
label.setFont(f);
label.setBackground(Color.GREEN);
label.setForeground(Color.BLUE);
add(label,"Center");
setVisible(true);
setSize(320,300);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==item1){
removeAll();
add(zengjia,"Center");
validate();
}
if(e.getSource()==item2){
removeAll();
add(chaxun,"Center");
validate();
}
if(e.getSource()==item3){
removeAll();
add(gengxin,"Center");
validate();
}
if(e.getSource()==item4){
removeAll();
add(shanchu,"Center");
validate();
}
if(e.getSource()==item5){
removeAll();
setBackground(Color.GREEN);
Label label=new Label("欢迎进入学生信息管理系统",Label.CENTER);
String s=" ";
Font f=new Font(s,Font.BOLD,22);
label.setFont(f);
label.setForeground(Color.BLUE);
add(label,"Center");
validate();
}
}
public static void main(String[] args)
{
tyj jesse=new tyj();
jesse.setVisible(true);
jesse.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
}
关于学生信息查询java代码和学生信息查询java代码是什么的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

    推荐阅读