Javabean+sql+jsp的简易学生信息管理系统

javabean+sql+jsp建立的简易管理系统

简易系统,并不完善,供学习使用

user.java

package com.fanchen.model;

public class User {
private String id;
private String name;
private int age;

public  String getId() {
    return id;
}

public void setId(String id) {
    this.id = id;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public  int getAge() {

    return age;
}

public void setAge(int age) {
    this.age = age;
}

}

userDao.java`

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class userDao implements Dao{
//添加
public void add(User user){
jdbcutil n = new jdbcutil();
Connection conn = jdbcutil.getConnection();
System.out.println(conn);
String sql = “insert into User(id,name,age) value(?,?,?)”;
try {
PreparedStatement pstmt =conn.prepareStatement(sql);
pstmt.setString(1,user.getId());
pstmt.setString(2,user.getName());
pstmt.setInt(3,user.getAge());
pstmt.executeUpdate();
}catch(SQLException e)
{
e.printStackTrace();
}
}
//修改
public void update(User user) {
Connection conn = jdbcutil.getConnection();//连接完成
User u = null;
String sql = “update tb_ceshi set id=?,name =?,age =?”;
u = new User();
try {
PreparedStatement pstmt = conn.prepareStatement(sql);

        pstmt.setString(2, u.getName());
        pstmt.setInt(3, u.getAge());
        pstmt.setString(1, u.getId());

    } catch (SQLException e) {
        e.printStackTrace();
    }
}

//按照id删除
public void deletebyid(String id) {
    Connection conn = jdbcutil.getConnection();
    String sql = "delete from tb_ceshi where id=?";
    try {
        PreparedStatement pstmt = conn.prepareStatement(sql);
        pstmt.setString(1, id);
        pstmt.executeLargeUpdate();
    } catch (SQLException e) {
        e.printStackTrace();
    }


}


//按照id查询
public User finduserbyid(String id) {
    Connection conn = jdbcutil.getConnection();
    User u = null;
    String sql = "select * from tb_ceshi where id=?";


    try {
        PreparedStatement pstmt = conn.prepareStatement(sql);
        pstmt.setString(1, id);
        ResultSet rs = pstmt.executeQuery();
        if (rs.next()) {
            u = new User();

            u.setName(rs.getString("name"));
            u.setId(rs.getString("id"));
            u.setAge(rs.getInt("age"));
        }

    } catch (SQLException e) {
        e.printStackTrace();
    }
    return u;
}

//显示所有记录
public List<User> Queryall() {
    List<User> list = new ArrayList();
    User a = null;
    Connection conn = jdbcutil.getConnection();
    String sql = "select * from tb_ceshi";
    try {
        Statement quan = conn.createStatement();

        ResultSet rs = quan.executeQuery(sql);

        while (rs.next()) {
            a = new User();
            a.setId(rs.getString("id"));
            a.setName(rs.getString("name"));
            a.setAge(rs.getInt("age"));
            list.add(a);
        }
        rs.close();
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        jdbcutil.closedb(conn);
    }
    return list;
}

}`

jdbcUnit.java

package com.fanchen.model;

import java.sql.*;

public class jdbcutil {
   
    private  static  Connection conn = null;
    private  static PreparedStatement pstmt = null;
    private  static ResultSet rs = null;

    public static Connection getConnection() {
   
        try {
   
            Class.forName
  • 3
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

快乐滴一只小青蛙

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值