Myeclipse 简单学生信息管理

本文介绍了如何在MyEclipse中创建一个简单的学生信息管理系统。首先通过Navicat创建数据库表,然后编写实体类、DAO层和Service层的Java代码,实现了用户登录验证、查询所有学生信息等功能。最后展示了添加学生信息的Servlet和对应的JSP页面。
摘要由CSDN通过智能技术生成

1.在Navicat数据库管理工具里创建3个表,t_user用户表,t_score学生成绩表,t_course表。

2.源代码

1.实体类比如学生类,用户类以此类推。

package com.pzhu.pojo;

public class Student {
    private int uid;
    private String uname;
    
    private int highmath;
    private int lisansx;
    private int english;
    private int caozuo;
    private double zfavg;
    
    private int cjdbh;
    private double xfavg;
    public int getUid() {
        return uid;
    }
    public void setUid(int uid) {
        this.uid = uid;
    }
    public String getUname() {
        return uname;
    }
    public void setUname(String uname) {
        this.uname = uname;
    }
    public int getHighmath() {
        return highmath;
    }
    public void setHighmath(int highmath) {
        this.highmath = highmath;
    }
    public int getLisansx() {
        return lisansx;
    }
    public void setLisansx(int lisansx) {
        this.lisansx = lisansx;
    }
    public int getEnglish() {
        return english;
    }
    public void setEnglish(int english) {
        this.english = english;
    }
    public int getCaozuo() {
        return caozuo;
    }
    public void setCaozuo(int caozuo) {
        this.caozuo = caozuo;
    }
    public double getZfavg() {
        return zfavg;
    }
    public void setZfavg(double zfavg) {
        this.zfavg = zfavg;
    }
    public int getCjdbh() {
        return cjdbh;
    }
    public void setCjdbh(int cjdbh) {
        this.cjdbh = cjdbh;
    }
    public double getXfavg() {
        return xfavg;
    }
    public void setXfavg(double xfavg) {
        this.xfavg = xfavg;
    }
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + caozuo;
        result = prime * result + cjdbh;
        result = prime * result + english;
        result = prime * result + highmath;
        result = prime * result + lisansx;
        result = prime * result + uid;
        result = prime * result + ((uname == null) ? 0 : uname.hashCode());
        long temp;
        temp = Double.doubleToLongBits(xfavg);
        result = prime * result + (int) (temp ^ (temp >>> 32));
        temp = Double.doubleToLongBits(zfavg);
        result = prime * result + (int) (temp ^ (temp >>> 32));
        return result;
    }
    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Student other = (Student) obj;
        if (caozuo != other.caozuo)
            return false;
        if (cjdbh != other.cjdbh)
            return false;
        if (english != other.english)
            return false;
        if (highmath != other.highmath)
            return false;
        if (lisansx != other.lisansx)
            return false;
        if (uid != other.uid)
            return false;
        if (uname == null) {
            if (other.uname != null)
                return false;
        } else if (!uname.equals(other.uname))
            return false;
        if (Double.doubleToLongBits(xfavg) != Double
                .doubleToLongBits(other.xfavg))
            return false;
        if (Double.doubleToLongBits(zfavg) != Double
                .doubleToLongBits(other.zfavg))
            return false;
        return true;
    }
    @Override
    public String toString() {
        return "Student [uid=" + uid + ", uname=" + uname + ", highmath="
                + highmath + ", lisansx=" + lisansx + ", english=" + english
                + ", caozuo=" + caozuo + ", zfavg=" + zfavg + ", cjdbh="
                + cjdbh + ", xfavg=" + xfavg + "]";
    }
    public Student(int uid, String uname, int highmath, int lisansx,
            int english, int caozuo, double zfavg, int cjdbh, double xfavg) {
        super();
        this.uid = uid;
        this.uname = uname;
        this.highmath = highmath;
        this.lisansx = lisansx;
        this.english = english;
        this.caozuo = caozuo;
        this.zfavg = zfavg;
        this.cjdbh = cjdbh;
        this.xfavg = xfavg;
    }
    public Student() {
        super();
        // TODO Auto-generated constructor stub
    }
    
}

2.编写dao层函数。

package com.pzhu.dao.impl;
//JDBC必须导入的包
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.pzhu.dao.StudentDao;

import com.pzhu.pojo.Student;
import com.pzhu.pojo.User;

public class StudentDaoImpl implements StudentDao{
        @Override
        public User checkLoginDao(String uname, String pwd) {
            //定义JDBC对象
            Connection conn=null;
            PreparedStatement ps=null;
            ResultSet rs=null;
            //定义用户对象并初始化,存储查询结果
            User u=null;
            
            try {
                //加载驱动
                Class.forName("com.mysql.jdbc.Driver");
                //获取连接
                conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/niit?useUnicode=true&characterEncoding=utf8","root","1234");
                //创建SQL语句
                String sql="select * from t_user where uname=? and pwd=?";
                //预处理
                ps=conn.prepareStatement(sql);
                //添加占位符
                ps.setString(1, uname);
                ps.setString(2, pwd);
                //执行SQL语句
                rs=ps.executeQuery();
                //遍历
                while(rs.next()){
                    u=new User();
                    u.setUid(rs.getInt("uid"));
                    u.setUname(rs.getString("uname"));
                    u.setPwd(rs.getString("pwd"));
                }
                
            } catch (Exception e) {
                // TODO: handle exception

  • 23
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值