精华内容
下载资源
问答
  • 1、修改窗体2、在StudentDao中增加修改学生信息的方法/*** 修改的方法** @param student* @return* @throws SQLException*/public boolean update(Student student) throws SQLException {DbUtil dbUtil = new ...

    1、修改窗体

    8a14c7534a77abf5f08ec19f12a26f16.gif

    c4f1dd58467f89deecf5c32a3321a1e4.png

    2、在StudentDao中增加修改学生信息的方法

    /**

    * 修改的方法

    *

    * @param student

    * @return

    * @throws SQLException

    */

    public boolean update(Student student) throws SQLException {

    DbUtil dbUtil = new DbUtil();

    String sql = "update tb_student set name='" + student.getName() + "',sno='"

    + student.getSno() + "',sex='" + student.getSex()

    + "',classname='" + student.getClassName() + "' where id ='"

    + student.getId() + "'";

    // 在控制台打印sql语句用于检查

    System.out.println(sql);

    // 处理并返回

    return dbUtil.execute(sql);

    }

    3、在StudentService中增加修改服务

    /**

    * 修改学生信息服务

    *

    * @param student

    * @return

    * @throws SQLException

    */

    public boolean editStudent(Student student) throws SQLException {

    StudentDao studentDao = new StudentDao();

    return studentDao.update(student);

    }

    4、给窗体中的表格添加点击事件

    a232d42054206ac86ca70e87ad5ae22f.gif

    表格单击完整代码

    table.addMouseListener(new MouseAdapter() {

    @Override

    public void mousePressed(MouseEvent e) {

    int row = table.getSelectedRow();

    textField_1.setText(table.getValueAt(row, 1) + "");

    textField_2.setText(table.getValueAt(row, 2) + "");

    String sex = table.getValueAt(row, 3) + "";

    if ("男".equals(sex)) {

    boy.setSelected(true);

    } else if ("女".equals(sex)) {

    girl.setSelected(true);

    }

    }

    });

    913f24740bfcfcaccac728f11fbb340d.gif

    5、提交并处理修改过的内容

    btnNewButton.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent e) {

    //获取学号

    String sno = textField_1.getText().trim();

    //获取姓名

    String name = textField_2.getText().trim();

    //获取性别

    String sex = "";

    if (boy.isSelected()) {

    sex = "男";

    } else if (girl.isSelected()) {

    sex = "女";

    }

    //获取班级

    String className = comboBox.getSelectedItem().toString();

    //说明id已经在前面保存了;

    //构建窗体

    Student student = new Student(id, sno, name, sex, className);

    try {

    if (service.editStudent(student)) {

    JOptionPane.showMessageDialog(null, "修改成功");

    } else {

    JOptionPane.showMessageDialog(null, "修改失败");

    }

    } catch (SQLException e1) {

    e1.printStackTrace();

    }

    }

    });

    6、截图

    16c46003196145f4aef7b1ee01472e4d.png

    7、完整代码

    package com.student.view;

    import java.awt.EventQueue;

    import java.sql.SQLException;

    import java.util.List;

    import javax.swing.ButtonGroup;

    import javax.swing.JFrame;

    import javax.swing.JOptionPane;

    import javax.swing.JPanel;

    import javax.swing.JScrollPane;

    import javax.swing.JTable;

    import javax.swing.border.EmptyBorder;

    import javax.swing.table.DefaultTableModel;

    import com.student.model.Student;

    import com.student.service.StudentService;

    import javax.swing.JLabel;

    import javax.swing.JTextField;

    import javax.swing.JButton;

    import java.awt.event.ActionListener;

    import java.awt.event.ActionEvent;

    import javax.swing.JRadioButton;

    import javax.swing.JComboBox;

    import javax.swing.DefaultComboBoxModel;

    import java.awt.event.MouseAdapter;

    import java.awt.event.MouseEvent;

    /*

    * 项目名称:

    *

    * 文件名称为:ShowStudent.java

    * 文件创建人:daxiang

    *

    * @author daxiang

    * @version

    * @time 2018年6月22日 上午8:03:24

    * @copyright daxiang

    */

    public class ShowStudent extends JFrame {

    private static final long serialVersionUID = 1L;

    private JPanel contentPane;

    private JTable table;

    private JTextField textField;

    private JLabel lblNewLabel;

    private JLabel lblNewLabel_1;

    private JLabel lblNewLabel_2;

    private JLabel lblNewLabel_3;

    private JTextField textField_1;

    private JTextField textField_2;

    private JRadioButton boy;

    private JRadioButton girl;

    private int id;// 保存修改时的ID

    /**

    * Launch the application.

    */

    public static void main(String[] args) {

    EventQueue.invokeLater(new Runnable() {

    public void run() {

    try {

    ShowTable frame = new ShowTable();

    frame.setVisible(true);

    } catch (Exception e) {

    e.printStackTrace();

    }

    }

    });

    }

    /**

    * Create the frame.

    */

    public ShowStudent() {

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    setBounds(100, 100, 860, 618);

    contentPane = new JPanel();

    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));

    setContentPane(contentPane);

    // 设置无布局

    contentPane.setLayout(null);

    // 创建滚动面板

    JScrollPane scrollPane = new JScrollPane();

    scrollPane.setBounds(37, 89, 739, 263);

    contentPane.add(scrollPane);

    // 创建表格

    table = new JTable();

    table.addMouseListener(new MouseAdapter() {

    @Override

    public void mousePressed(MouseEvent e) {

    int row = table.getSelectedRow();

    id = (int) table.getValueAt(row, 0);

    textField_1.setText(table.getValueAt(row, 1) + "");

    textField_2.setText(table.getValueAt(row, 2) + "");

    String sex = table.getValueAt(row, 3) + "";

    if ("男".equals(sex)) {

    boy.setSelected(true);

    } else if ("女".equals(sex)) {

    girl.setSelected(true);

    }

    }

    });

    // 将表格加载到滚动面板

    scrollPane.setViewportView(table);

    try {

    // 创建服务

    StudentService service = new StudentService();

    // 查询出所有学生

    List list = service.getStudent();

    // 装载数据

    fillTable(list);

    JLabel label = new JLabel("请输入学生姓名:");

    label.setBounds(93, 43, 123, 18);

    contentPane.add(label);

    textField = new JTextField();

    textField.setBounds(242, 40, 169, 24);

    contentPane.add(textField);

    textField.setColumns(10);

    JButton button = new JButton("查 找");

    button.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent e) {

    try {

    // 获取查询数据

    // textField.getText().trim()获取文本框数据并且去掉空格

    List list1 = service.getStudent(textField

    .getText().trim());

    // 装载到表格

    fillTable(list1);

    } catch (SQLException e1) {

    e1.printStackTrace();

    }

    }

    });

    button.setBounds(477, 39, 113, 27);

    contentPane.add(button);

    lblNewLabel = new JLabel("学 号");

    lblNewLabel.setBounds(86, 383, 52, 18);

    contentPane.add(lblNewLabel);

    lblNewLabel_1 = new JLabel("姓名");

    lblNewLabel_1.setBounds(306, 383, 43, 18);

    contentPane.add(lblNewLabel_1);

    lblNewLabel_2 = new JLabel("班 级");

    lblNewLabel_2.setBounds(86, 438, 52, 18);

    contentPane.add(lblNewLabel_2);

    lblNewLabel_3 = new JLabel("性别");

    lblNewLabel_3.setBounds(516, 383, 43, 18);

    contentPane.add(lblNewLabel_3);

    textField_1 = new JTextField();

    textField_1.setBounds(152, 380, 140, 24);

    contentPane.add(textField_1);

    textField_1.setColumns(10);

    textField_2 = new JTextField();

    textField_2.setBounds(363, 380, 123, 24);

    contentPane.add(textField_2);

    textField_2.setColumns(10);

    ButtonGroup buttonGroup = new ButtonGroup();

    boy = new JRadioButton("男");

    boy.setBounds(571, 379, 52, 27);

    contentPane.add(boy);

    girl = new JRadioButton("女");

    girl.setBounds(639, 379, 52, 27);

    contentPane.add(girl);

    buttonGroup.add(girl);

    buttonGroup.add(boy);

    JComboBox comboBox = new JComboBox();

    comboBox.setModel(new DefaultComboBoxModel(new String[] {

    "计科1班", "计科2班", "计科3班", "计科4班" }));

    comboBox.setBounds(152, 435, 140, 24);

    contentPane.add(comboBox);

    JButton btnNewButton = new JButton("修 改");

    // 处理修改

    btnNewButton.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent e) {

    // 获取学号

    String sno = textField_1.getText().trim();

    // 获取姓名

    String name = textField_2.getText().trim();

    // 获取性别

    String sex = "";

    if (boy.isSelected()) {

    sex = "男";

    } else if (girl.isSelected()) {

    sex = "女";

    }

    // 获取班级

    String className = comboBox.getSelectedItem().toString();

    // 说明id已经在前面保存了;

    // 构建窗体

    Student student = new Student(id, sno, name, sex, className);

    try {

    if (service.editStudent(student)) {

    JOptionPane.showMessageDialog(null, "修改成功");

    } else {

    JOptionPane.showMessageDialog(null, "修改失败");

    }

    } catch (SQLException e1) {

    e1.printStackTrace();

    }

    }

    });

    btnNewButton.setBounds(346, 434, 113, 27);

    contentPane.add(btnNewButton);

    JButton btnNewButton_1 = new JButton("删除");

    btnNewButton_1.setBounds(516, 434, 113, 27);

    contentPane.add(btnNewButton_1);

    } catch (SQLException e) {

    // TODO Auto-generated catch block

    e.printStackTrace();

    }

    setVisible(true);

    }

    /**

    * 表格装载数据

    *

    * @param list

    */

    public void fillTable(List list) {

    // 将默认的加载数据去掉,重新定义个表头

    String[] head = new String[] { "序号", "学号", "姓名", "性别", "班级" };

    // 创建一个二维数组,5表示列数

    Object[][] data = new Object[list.size()][5];

    // 遍历

    for (int i = 0; i < list.size(); i++) {

    data[i][0] = list.get(i).getId();

    data[i][1] = list.get(i).getSno();

    data[i][2] = list.get(i).getName();

    data[i][3] = list.get(i).getSex();

    data[i][4] = list.get(i).getClassName();

    }

    // 将数据和表头封装

    DefaultTableModel datamoModel = new DefaultTableModel(data, head);

    // 将封装好的数据加载

    table.setModel(datamoModel);

    }

    }

    展开全文
  • package Week;import jdk.internal.util.xml.impl....import java.util.HashSet;import java.util.Scanner;public class StudentMs {Scanner sc = new Scanner(System.in);public int getID() {return ID;}public...

    package Week;

    import jdk.internal.util.xml.impl.Input;

    import java.util.HashSet;

    import java.util.Scanner;

    public class StudentMs {

    Scanner sc = new Scanner(System.in);

    public int getID() {

    return ID;

    }

    public String getName() {

    return name;

    }

    public String getClassnum() {

    return classnum;

    }

    public int getTelephone() {

    return telephone;

    }

    public void setID(int ID) {

    this.ID = ID;

    }

    public void setName(String name) {

    this.name = name;

    }

    public void setClassnum(String classnum) {

    this.classnum = classnum;

    }

    public void setTelephone(int telephone) {

    this.telephone = telephone;

    }

    private int ID;

    private String name;

    private String classnum;

    private int telephone;

    /* public StudentMs(int ID, String name, String classnum, String telephone) {

    this.ID = ID;

    this.name = name;

    this.classnum = classnum;

    this.telephone = telephone;

    }*/

    public void add(StudentMs a){

    int ID1;

    String name2;

    String classnum1;

    int telephone1;

    System.out.println("请输入你要添加的学生信息");

    System.out.println("请输出学生学号");

    ID1 =sc.nextInt();

    a.setID(ID1);

    System.out.println("请输出学生姓名");

    sc.nextLine();

    name2=sc.nextLine();

    a.setName(name2);

    System.out.println("请输出学生班级");

    classnum1=sc.nextLine();

    a.setClassnum(classnum1);

    System.out.println("请输出学生电话号码");

    telephone1=sc.nextInt();

    a.setTelephone(telephone1);

    }

    public int find(String[][] a)

    {

    System.out.println("请输入你要查询学生的学号");

    int n=-1;

    int id = sc.nextInt();

    for(int i=0;i

    {

    if(Integer.parseInt(a[i][0]) == id)

    {

    n=i;

    break;

    }

    }

    return n;

    }

    public int delay(String[][] a)

    {

    System.out.println("请输入你要删除学生的学号!");

    int id;

    int n=-1;

    id= sc.nextInt();

    for(int i=0;i

    {

    if(Integer.parseInt(a[i][0])==id)

    {

    n=i;

    break;

    }

    }

    return n;

    }

    public int print(String[][] a)

    {

    System.out.println("请输入你要打印的学生信息的学生学号!");

    int id;

    int n=-1;

    id = sc.nextInt();

    for(int i=0;i

    {

    if(Integer.parseInt(a[i][0]) == id)

    {

    n=i;

    break;

    }

    }

    return n;

    }

    public int recivice(String[][] a)

    {

    System.out.println("请输入你要修改的学生信息的学生学号!");

    int id;

    int n=-1;

    id = sc.nextInt();

    for(int i=0;i

    {

    if(Integer.parseInt(a[i][0]) == id)

    {

    n=i;

    break;

    }

    }

    return n;

    }

    public int Num(){//用来查找修改图书信息的下标

    System.out.println("选择你要修改的内容:0.学号 1.姓名 2.班级 3.电话");

    int n=sc.nextInt();

    return n;

    }

    public void display()

    {

    System.out.println("***************************************");

    System.out.println("**** 高校学习信息管理系统 *****");

    System.out.println("**** 1:添加学生信息 ****");

    System.out.println("**** 2:查询学生信息 ****");

    System.out.println("**** 3:修改学生信息 ****");

    System.out.println("**** 4:删除学生信息 ****");

    System.out.println("**** 5:打印学生信息 ****");

    System.out.println("**** 6:退出 ****");

    System.out.println("**** 请输入您要进行的操作(1-6) ***");

    }

    public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    StudentMs studentMs = new StudentMs();

    boolean flat = true;

    HashSet a = new HashSet();

    String[][] student=new String[4][10];

    int num=0;

    int number;

    int m,n;

    while (flat)

    {

    studentMs.display();

    number=sc.nextInt();

    switch (number)

    {

    case 1:

    {

    studentMs.add(studentMs);

    student[num][0]=studentMs.ID+"";

    student[num][1]=studentMs.name+"";

    student[num][2]=studentMs.classnum+"";

    student[num][3]=studentMs.telephone+"";

    num++;

    break;

    }

    case 2:

    {

    m=studentMs.find(student);

    if(m>=0){

    System.out.println("学生学号为:"+student[m][0]);

    System.out.println("学生姓名为:"+student[m][1]);

    System.out.println("学生班级为:"+student[m][2]);

    System.out.println("学生电话为:"+student[m][3]);

    }else{

    System.out.println("学号错误,未找到学生");

    break;

    }

    break;

    }

    case 3:

    {

    m=studentMs.recivice(student);

    n=studentMs.Num();

    System.out.println("请输入你要修改的内容:");

    student[m][n]=sc.next();

    System.out.println("修改成功!");

    break;

    }

    case 4:

    {

    m=studentMs.delay(student);

    for(int i=0;i<4;i++)

    {

    student[m][i]=null;

    }

    System.out.println("已经成功删除学生信息");

    break;

    }

    case 5:

    {

    m=studentMs.delay(student);

    System.out.println("学号"+student[m][0]+"的学生信息为:");

    System.out.println("学生学号为:"+student[m][0]);

    System.out.println("学生姓名为:"+student[m][1]);

    System.out.println("学生班级为:"+student[m][2]);

    System.out.println("学生电话为:"+student[m][3]);

    break;

    }

    case 6:

    {

    System.out.println("程序退出!");

    flat=false;

    break;

    }

    }

    }

    }

    }

    展开全文
  • 添加学生信息(性别,班级,学号)并提供修改java参考代码。
  • 修改信息页面UI界面如下,当正确修改数据库的内容时,可在下方显示修改成功: UI界面设计如下: package ui; import java.awt.Container; import java.awt.Font; import java.awt.GridLayout; import java.awt....

    修改信息页面UI界面如下,当正确修改数据库的内容时,可在下方显示修改成功:
    在这里插入图片描述
    UI界面设计如下:

    package ui;
    
    import java.awt.Container;
    import java.awt.Font;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    
    import daoImp.ClassesDaoImp;
    import entity.Classes;
    
    public class Update extends JFrame implements ActionListener {
    	JLabel title,number,name,teacher,lbl;
    	JTextField num,nme,tea;
    	JButton dft,cla,rtn;
    	JPanel line,line1,line2,line3,line4,line5;
    
    	public Update() {
    		// TODO Auto-generated constructor stub
    		Container con=getContentPane();
    		con.setLayout(new GridLayout(6,1));
    		line=new JPanel();
    		line1=new JPanel();
    		line2=new JPanel();
    		line3=new JPanel();
    		line4=new JPanel();
    		line5=new JPanel();
    		title=new JLabel("学生管理系统");
    		title.setFont(new Font("黑体", Font.PLAIN, 20));
    		number=new JLabel("学号:");
    		name=new JLabel("修改后姓名:");
    		teacher=new JLabel("修改后教师:");
    		lbl=new JLabel();
    		num=new JTextField(10);
    		nme=new JTextField(10);
    		tea=new JTextField(10);
    		dft=new JButton("确定");
    		dft.addActionListener(this);
    		cla=new JButton("清空");
    		cla.addActionListener(new ActionListener() {
    			
    			@Override
    			public void actionPerformed(ActionEvent e) {
    				// TODO Auto-generated method stub
    				num.setText("");
    				nme.setText("");
    				tea.setText("");
    				lbl.setText("");
    			}
    		});
    		rtn=new JButton("返回");
    		rtn.addActionListener(new ActionListener() {
    			
    			@Override
    			public void actionPerformed(ActionEvent e) {
    				// TODO Auto-generated method stub
    				setVisible(false);
    				new Host().setVisible(true);
    			}
    		});
    		line.add(title);
    		line1.add(number);
    		line1.add(num);
    		line2.add(name);
    		line2.add(nme);
    		line3.add(teacher);
    		line3.add(tea);
    		line4.add(dft);
    		line4.add(cla);
    		line4.add(rtn);
    		line5.add(lbl);
    		con.add(line);
    		con.add(line1);
    		con.add(line2);
    		con.add(line3);
    		con.add(line4);
    		con.add(line5);
    		setTitle("修改学生信息");
    		setSize(340,300);
    		setVisible(true);
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	}
    	
    
    	@Override
    	public void actionPerformed(ActionEvent e) {
    		// TODO Auto-generated method stub
    		ClassesDaoImp cdi=new ClassesDaoImp();
    		Classes cu=new Classes();
    		cu.setNum(num.getText());
    		cu.setName(nme.getText());
    		cu.setTeacher(tea.getText());
    		if(cdi.update(cu)) {
    			lbl.setText("修改成功");
    		}else {
    			lbl.setText("查无此人");
    		}
    
    	}
    
    }
    
    

    重写ClassesDaoImp类的修改方法,实现将修改数据库信息的功能:

    package daoImp;
    
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.List;
    
    import dao.classesDao;
    import db.DBCon;
    import entity.Classes;
    
    public class ClassesDaoImp implements classesDao {
    	Connection cn;
    	PreparedStatement psm=null;
    	private ResultSet rs;
    
    	@Override
    	public boolean add(Classes classes) throws SQLException {
    		// TODO Auto-generated method stub
    		//。。。。。。
    		return flag;
    	}
    
    	@Override
    	public boolean delete(String num) {
    		// TODO Auto-generated method stub
    		//。。。。。。
    		return flag;
    	}
    
    	@Override
    	public boolean update(Classes classes) {
    		// TODO Auto-generated method stub
    		boolean flag=false;
    		DBCon dbcon=new DBCon();
    		cn=dbcon.getConnection();
    		String sql="update classes set name=?,teacher=? where num=?";
    		try {
    			psm=cn.prepareStatement(sql);
    			psm.setString(1, classes.getName());
    			psm.setString(2, classes.getTeacher());
    			psm.setString(3, classes.getNum());
    			if(psm.executeUpdate()!=0) {
    				flag=true;
    			}
    			psm.close();
    			cn.close();
    		} catch (SQLException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		return flag;
    	}
    
    	@Override
    	public Classes SearchByNum(String num) {
    		// TODO Auto-generated method stub
    		return null;
    	}
    
    	@Override
    	public List<Classes> sreachByTeacher(String teacher) {
    		// TODO Auto-generated method stub
    		return null;
    	}
    
    }
    
    
    展开全文
  • 错误原因:1.Java web 的Servlet类没有配置好,并且缺少一个 Dao类(Date Access Object通常用于操作数据库的).2.代码的某些名称错误,导致数据库数据存储错误。添加的Dao类如下:1 packagecom.Dao;23 importjava.sql...

    错误原因:

    1.Java web 的Servlet类没有配置好,并且缺少一个 Dao类(Date Access Object通常用于操作数据库的).

    2.代码的某些名称错误,导致数据库数据存储错误。

    添加的Dao类如下:

    1 packagecom.Dao;2

    3 importjava.sql.Connection;4 importjava.sql.PreparedStatement;5 importjava.sql.ResultSet;6 importjava.sql.SQLException;7 importjava.sql.Statement;8 importjava.util.ArrayList;9 importjava.util.List;10 importcom.DBUtil.UserDBUtil;11

    12 importjdk.nashorn.internal.ir.RuntimeNode.Request;13

    14 public classDao {15 public booleanadd(String username,String password,String name,String studentID,String sex,String phone,String email,String xueyuan,String xi,String classes,String year,String shengyuandi,String beizhu) {16 String sql = "insert into use02 values ('" + username + "','" + password +"','" + name +"','" +studentID +"','" + sex +"','" +phone +"','" + email +"','" +xueyuan +"','"+xi +"','"+classes +"','"+year+"','"+shengyuandi +"','"+beizhu +"')";17 //创建数据库链接

    18 Connection conn =UserDBUtil.getConnection();19 Statement state = null;20 boolean f = false;21 int a = 0;22 try{23 state =conn.createStatement();24 a =state.executeUpdate(sql);25 } catch(Exception e) {26 e.printStackTrace();27 } finally{28 //关闭z 连接29 //DB.close(state, conn);

    30 }31

    32 if (a > 0) {33 f = true;34 }35 returnf;36 }37 }

    修改后的Servlet代码如下:

    1 importjava.io.IOException;2

    3

    4 importjavax.servlet.ServletException;5 importjavax.servlet.ServletRequest;6 importjavax.servlet.annotation.WebServlet;7 importjavax.servlet.http.HttpServlet;8 importjavax.servlet.http.HttpServletRequest;9 importjavax.servlet.http.HttpServletResponse;10

    11 import com.Dao.*;12 import com.DBUtil.*;13

    14 /**

    15 * Servlet implementation class UserServlet16 */

    17 @WebServlet("/AddServlet")18 public class AddServlet extendsHttpServlet {19 private static final long serialVersionUID = 1L;20

    21 /**

    22 *@seeHttpServlet#HttpServlet()23 */

    24 publicAddServlet() {25 super();26 //TODO Auto-generated constructor stub

    27 }28 Dao dao = newDao();29

    30 protected void service(HttpServletRequest req, HttpServletResponse resp) throwsServletException, IOException {31 req.setCharacterEncoding("utf-8");32 String method = req.getParameter("method");33 if ("add".equals(method)) {34

    35 add(req, resp);36 System.out.println("!!!");37 }38 }39 private void add(HttpServletRequest req, HttpServletResponse resp) throwsIOException, ServletException {40 //TODO Auto-generated method stub

    41 String username = req.getParameter("username");42 String password = req.getParameter("password");43 String name = req.getParameter("name");44 String studentID = req.getParameter("studentID");45 String sex = req.getParameter("sex");46 String phone = req.getParameter("phone");47 String email = req.getParameter("email");48 String xueyuan = req.getParameter("xueyuan");49 String xi = req.getParameter("xi");50 String classes = req.getParameter("classes");51 String year = req.getParameter("year");52 String shengyuandi = req.getParameter("shengyuandi");53 String beizhu = req.getParameter("beizhu");54 if(dao.add(username,password,name,studentID,sex,phone,email,xueyuan,xi,classes,year,shengyuandi,beizhu)) {55 req.setAttribute("message", "注册成功!");56 req.getRequestDispatcher("index1.jsp").forward(req, resp);57 return;58 }else{59 req.setAttribute("message", "账号重复,请重新输入!");60 req.getRequestDispatcher("index1.jsp").forward(req, resp);61 return;62 }63 //req.getRequestDispatcher("index1.jsp").forward(req, resp);

    64 }65

    66

    67 }

    bean类

    1 public classUser {2 privateString username;3 privateString password;4 privateString name;5 privateString studentID;6 privateString sex;7 privateString phone;8 privateString email;9 privateString xueyuan;10 privateString xi;11 privateString classes;12 privateString year;13 privateString shengyuandi;14 privateString beizhu;15 publicString getUsername() {16 returnusername;17 }18 public voidsetUsername(String username) {19 this.username =username;20 }21 publicString getPassword() {22 returnpassword;23 }24 public voidsetPassword(String password) {25 this.password =password;26 }27 publicString getName() {28 returnname;29 }30 public voidsetName(String name) {31 this.name =name;32 }33 publicString getStudentID() {34 returnstudentID;35 }36 public voidsetStudentID(String studentID) {37 this.studentID =studentID;38 }39 publicString getSex() {40 returnsex;41 }42 public voidsetSex(String sex) {43 this.sex =sex;44 }45 publicString getPhone() {46 returnphone;47 }48 public voidsetPhone(String phone) {49 this.phone =phone;50 }51 publicString getEmail() {52 returnemail;53 }54 public voidsetEmail(String email) {55 this.email =email;56 }57 publicString getXueyuan() {58 returnxueyuan;59 }60 public voidsetXueyuan(String xueyuan) {61 this.xueyuan =xueyuan;62 }63 publicString getXi() {64 returnxi;65 }66 public voidsetXi(String xi) {67 this.xi =xi;68 }69 publicString getClasses() {70 returnclasses;71 }72 public voidsetClasses(String classes) {73 this.classes =classes;74 }75 publicString getYear() {76 returnyear;77 }78 public voidsetYear(String year) {79 this.year =year;80 }81 publicString getShengyuandi() {82 returnshengyuandi;83 }84 public voidsetShengyuandi(String shengyuandi) {85 this.shengyuandi =shengyuandi;86 }87 publicString getBeizhu() {88 returnbeizhu;89 }90 public voidsetBeizhu(String beizhu) {91 this.beizhu =beizhu;92 }93 publicUser(String username, String password, String name, String studentID, String sex, String phone, String email,94 String xueyuan, String xi, String classes, String year, String shengyuandi, String beizhu) {95 super();96 this.username =username;97 this.password =password;98 this.name =name;99 this.studentID =studentID;100 this.sex =sex;101 this.phone =phone;102 this.email =email;103 this.xueyuan =xueyuan;104 this.xi =xi;105 this.classes =classes;106 this.year =year;107 this.shengyuandi =shengyuandi;108 this.beizhu =beizhu;109 }110

    111

    112

    113 }

    数据库连接程序:

    1 importjava.sql.Connection;2

    3 importjava.sql.DriverManager;4 //import java.sql.ResultSet;

    5 importjava.sql.SQLException;6 //import java.sql.Statement;

    7

    8 public classUserDBUtil {9 staticConnection con;10 public staticConnection getConnection() {11 try{12 Class.forName("com.mysql.cj.jdbc.Driver");13 System.out.println("数据库驱动加载成功");14 } catch(ClassNotFoundException e) {15 //TODO Auto-generated catch block

    16 e.printStackTrace();17 }18

    19 try{20 con=DriverManager.getConnection("jdbc:mysql://localhost:3306/user?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B88&serverTimezone=GMT%2B8&useSSL=false","root","101032");21 System.out.println("数据库链接成功!");22 } catch(SQLException e) {23 //TODO Auto-generated catch block

    24 e.printStackTrace();25 }26

    27 returncon;28 }29

    30 public static voidmain(String[] args) {31 UserDBUtil c=newUserDBUtil();32 c.getConnection();33

    34 }

    jsp 页面源代码实现:

    1

    2 pageEncoding="UTF-8"%>

    3

    4

    5

    6

    7

    用户注册

    8

    9

    10

    11

    12

    13

    14

    15

    16 登陆账号

    17

    18

    19

    20 登陆密码

    21

    22

    23

    24 姓名

    25

    26

    27

    28 学号

    29

    30

    31

    32 性别

    33 男34  35 女36

    37

    38

    39

    40

    41

    42

    43

    44

    45

    46 手机号

    47

    48

    49

    50

    51

    52

    53

    54 所在学院:

    55

    56

    57

    58 所在系:

    59

    60

    61

    62 所在班级:

    63

    64

    65

    66

    67 入学年份(届):

    68

    69 2014

    70 2015

    71 2016

    72 2017

    73 2018

    74 2019

    75

    76

    77

    78 生源地:

    79

    80

    81

    82 备注:

    83

    84

    85

    86

    87

    88

    89

    90

    91

    92

    93

    94 //正则表达式

    95 function check(form){96

    97 if(form.username.value.length<6 || form.username.value.length>12 || new RegExp("[^0-9a-zA-Z]").test(form.username.value)){98 alert("登陆账号必须由6-12位英文字符或数字组成!");99 form.user.focus();100 return false;101 }102 if(new RegExp("[^a-zA-Z]").test(form.username.value.substring(0,1))){103 alert("登陆账号必须以英文字母开头!");104 form.user.focus();105 return false;106 }107 if(form.password.value.length <= 8 || new RegExp("[^0-9a-zA-Z]").test(form.password.value)){108 alert("密码必须由八位以上字母、数字组成!");109 form.phone.focus();110 return false;111 }112 if(form.studentID.value.length != 8 || new RegExp("[^0-9]").test(form.studentID.value)){113 alert("请输入八位学号!");114 form.phone.focus();115 return false;116 }117

    118 if(form.phone.value.length != 11 || new RegExp("[^0-9]").test(form.phone.value)){119 alert("手机号请输入11位数字!");120 form.phone.focus();121 return false;122 }123

    124 //以数字字母开头,中间可以是多个数字字母或下划线;然后是“@”;然后是数字字母;然后是“.”;最后是2-4个字母结尾

    125 var regex = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;126 if(!regex.test(form.email.value)){127 alert("邮箱格式错误!");128 form.email.focus();129 return false;130 }131 return true;132 }133

    134

    135

    136

    数据库存储界面:

    3becd6e58c88da940d2f08c541a155d3.png

    对于Java web数据库连接的理解:

    Java类:

    1.servlet 类 处理从前端接受的信息,即jsp 与数据库连接的接口

    2.DBUtil 类  加载数据库驱动, 建立对数据库的连接。

    3.Dao 类  实现对数据库的增删改查

    4.Bean 类 存储信息的基础类

    5.在lib目录下导入需要的jar的包

    84e197356ed4fad97fb9a1df25e3bb3e.png

    6. jsp 实现界面。

    本人目前处于初学阶段,代码大部分都是对模板进行修改,没有完全理解,仍旧有许多需要学习的地方。

    数据库的JDBC桥接:

    面向对象的应用程序接口,制定了统一的访问各种关系型数据库的标准接口。

    JDBC任务:

    1.与数据库建立连接

    2.向数据库发生sql语句

    3.处理从数据库返回的结果

    以下是之前的错误代码:

    https://www.cnblogs.com/cxy0210/p/11715924.html

    以上代码如有错误,敬请指正,感激不尽。

    展开全文
  • java 学生信息管理系统

    万次阅读 多人点赞 2015-10-06 14:03:33
    学生信息管理包括添加,删除,修改,查询,显示全部等 具体结构如图 在SQL Server 2005数据库上实现数据操作。使用纯面向对象的java语言作为开发语言 在sql server 2005新建一个名为Student的数据库,在下面新建一...
  • package Week;import jdk.internal.util.xml.impl....import java.util.HashSet;import java.util.Scanner;public class StudentMs {Scanner sc = new Scanner(System.in);public int getID() {return ID;}public...
  • java 代码编写 能够实现学生信息的添加,删除,修改.
  • 2、在StudentDao中增加修改学生信息的方法 /** * 修改的方法 * * @param student * @return * @throws SQLException */ public boolean update(Student student) throws SQLException { ....
  • 简单学生信息获取及修改java

    千次阅读 2018-09-23 12:22:39
    class ShowTotalMessage{ //显示学生所有信息 public static void showTotalMessage(Student student1) { System.out.println(&quot;该同学id: &quot;+student1.getid()); System.out.println(&...
  • java的那些事:实现学生信息录入和查看本程序可以实现学生...(3)修改学生信息:由用户输入学生的学号,程序验证是否有此学生,有此学生则修改学生的其他信息(注意学号不能修改)。无此学生则给出相应提示。(4)删除...
  • 简单学生信息管理系统java课程设计_计算机软件及应用_IT/计算机_专业资料。数据库课程设计 -简单学生信息管理系统...使用 Java 程序编写,能够进行学生信息录入、修改、 查看......JAVA 程序设计 课程设计报告 课题...
  • 基于java学生信息管理系统中分为多级角色管理:包括系统管理员、学生和老师几种权限,采用了开发技术JSP以及MYSQL数据库作为本系统的开发工具.主要包括新闻模块,考试模块,学生模块,教师模块,选课模块等本系统分为...
  • java学生信息管理

    2014-12-19 09:29:12
    java学生信息管理系统源代码。本系统主要完成对学生信息的管理,包括录入、添加、修改、删除、查询、打印信息等方面。系统可以完成对各类系统浏览、查询、添加、删除、修改等功能。
  • 建立一个ACCESS数据库,其中有学生信息表,编写JAVA代码,建立登陆,查询,删除,修改等界面并对学生信息表进行查询添加修改删除操作
  • 学生信息crud java代码

    2010-06-08 16:54:40
    学生信息crud java代码 适合新手 连接数据库并对学生信息创建删除修改增加
  • java学生信息管理系统

    2018-07-13 14:53:00
    java学生信息管理系统:实现功能: 1,登录系统时-要登录,注册; 2,对学生:(1)查询所有,查询年级;(2)增加学生,修改学生信息;(3)删除学生,(4)退出系统 单纯javase,没用swing,纯控制台查看
  • 学生信息管理Java程序

    2011-11-12 21:39:23
    Java编写的学生信息管理系统,可以实现学生信息的增加,删除,修改以及管理程序。
  • System.out.println("3、修改学生信息"); System.out.println("4、查询学生信息"); System.out.println("请输入操作项,点击Enter键"); Scanner scanner = new Scanner(System.in);//Ctrl+Shift+O ...
  • 编写增加和修改和查询时,要以唯一识别的学号进行操作4.学号是唯一的,可通过遍历集合中的序号与输入键盘中的学号进行比较项目截图:运行截图:程序源代码:Student.javapackage Students;public class Stud...
  • 本系统是利用Java知识使用Eclipse实现的学生信息的录入、修改、显示、删除
  • java web学生信息管理系统,包含了登录,还有验证码功能。成绩录入,修改学生信息录入修改查询等等功能,代码清晰易懂,无错误
  • java学生信息管理模块

    2015-03-19 17:40:35
    基于java纯代码的简易学生信息管理模块。在控制台打印,满足老师布置的小练习。对用户的输入,例如:学号、姓名、性别、年龄都进行的正则表达式匹配。对于要修改学生的信息,采用简单的Json格式处理,自定义处理此...
  • JAVA简单写学生信息管理系统,实现学生信息的输入、查询、修改、删除操作package Week;import jdk.internal.util.xml.impl.Input;import java.util.HashSet;import java.util.Scanner;public class StudentMs {...
  • 不废话,上代码: package keeper;... //Java封装 private String id; private String name; private String mobile; private String address; public String getId() { return id; } publi...
  • Java学生信息管理系统

    2020-09-25 14:06:06
    (无数据库)txt文件进行保存数据有完整的登录注册和学生信息录入界面1.登录界面:有登录,注册,重置功能,实现用户登录和无用户人员注册登录账号以及登录密码,注册完成的账号密码可登录系统,重置按钮拥有对输错...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 1,476
精华内容 590
关键字:

修改学生信息java

java 订阅