zoukankan      html  css  js  c++  java
  • 每日随笔

    继续重写选课系统,servlet的创建有些冗杂,可以更加简化

    public boolean Insert(student stu) {
    boolean f = false;
    Connection connection = DBUtil_Student.getConnection();

    PreparedStatement preparedStatement = null;
    try {
    String sql = "insert into student(id,name,sex,classes,major) values ('" + stu.getId() + "','"
    + stu.getName() + "','" + stu.getSex() + "','" + stu.getClasses() + "','" + stu.getMajor() + "')";// 执行语句
    preparedStatement = connection.prepareStatement(sql);// 执行语句的转化
    preparedStatement.executeUpdate(sql);
    f = true;
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } finally {
    // DBUtil.close(resultSet);
    DBUtil_Student.close(preparedStatement);
    DBUtil_Student.close(connection);
    }
    return f;
    }

    @SuppressWarnings("finally")
    public student Select(int id) {
    String sql = "select * from student where id='" + id + "'";
    Connection conn = DBUtil_Student.getConnection();
    PreparedStatement st = null;
    student stu = null;
    ResultSet rs = null;
    try {
    st = conn.prepareStatement(sql);
    st.executeQuery(sql);
    rs = st.executeQuery(sql);
    while (rs.next()) {
    String name = rs.getString("name");
    String sex = rs.getString("sex");
    String classes = rs.getString("classes");
    String major = rs.getString("major");
    stu = new student(id, name, sex, classes, major);
    }
    } catch (Exception e) {
    // TODO: handle exception
    e.printStackTrace();
    } finally {
    DBUtil_Student.close(conn);
    DBUtil_Student.close(st);
    DBUtil_Student.close(rs);
    return stu;
    }
    }

  • 相关阅读:
    装饰器模式
    java构建树形节点优化
    excel操作
    回调函数
    网络编程
    小练习-接口发布文章 验证未登录
    requests模块
    try异常处理
    内置函数
    接口-用户登录,返回session
  • 原文地址:https://www.cnblogs.com/buxiang-Christina/p/14158872.html
Copyright © 2011-2022 走看看