• web练习


    11.22

    今天练习了web项目,打算开发我第一个大型的系统,没遇到什么问题,明天计划继续练习web项目;

    代码部分:

    package com.pp;

    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.SQLException;

    public class dao {
    public void insert(get L) throws SQLException {
    String sql = "insert into xuesheng(xuehao,xingming,banji,kecheng,fenshu) values(?,?,?,?,?)";
    Connection connection = DBU.getConnection();
    PreparedStatement preparedStatement = null;
    preparedStatement = connection.prepareStatement(sql);
    preparedStatement.setString(1,L.getXuehao());
    preparedStatement.setString(2,L.getXingming());
    preparedStatement.setString(3,L.getBanji());
    preparedStatement.setString(4,L.getKecheng());
    preparedStatement.setString(5,L.getFenshu());
    preparedStatement.execute();
    }
    public void update(String xuehao,String xingming,String banji,String kecheng,String fenshu) throws SQLException {
    String sql="UPDATE xuesheng SET xuehao=?,xingming=?,banji=?,kecheng=? fenshu=?";
    Connection conn= DBU.getConnection();
    PreparedStatement papre=conn.prepareStatement(sql);
    papre.setString(1, xuehao);
    papre.setString(2, xingming);
    papre.setString(3, banji);
    papre.setString(4, kecheng);
    papre.setString(5, fenshu);
    papre.execute();
    }
    public void delete(String xingming) throws SQLException {
    String sql="delete from xuesheng where xingming=?";
    Connection conn= DBU.getConnection();
    PreparedStatement papre=conn.prepareStatement(sql);
    papre.setString(1, xingming);
    papre.execute();
    }
    }

    package com.pp;
    import java.sql.*;
    public class DBU{
    private DBU() {}
    static {
    try {
    Class.forName("com.mysql.jdbc.Driver");
    }catch(ClassNotFoundException e) {
    e.printStackTrace();
    }
    }
    public static Connection getConnection() throws SQLException{
    return DriverManager.getConnection("jdbc:mysql://localhost:3306/user?serverTimezone=UTC&useUnicode=true&zeroDateTimeBehavior=convertToNull&autoReconnect=true&characterEncoding=utf-8","root","123456");
    }
    public static void close(Connection conn,Statement ps,ResultSet rs) {
    if(rs!=null) {
    try {
    rs.close();
    }catch(SQLException s) {
    s.printStackTrace();
    }
    }
    if(ps!=null) {
    try {
    ps.close();
    }catch(SQLException s) {
    s.printStackTrace();
    }
    }
    if(conn!=null) {
    try {
    conn.close();
    }catch(SQLException s) {
    s.printStackTrace();
    }
    }
    }
    }

    package com.pp;

    public class get {
    String xuehao;
    String xingming;
    String banji;
    String kecheng;
    String fenshu;



    public String getXuehao() {
    return xuehao;
    }

    public void setXuehao(String xuehao) {
    this.xuehao = xuehao;
    }

    public String getXingming() {
    return xingming;
    }

    public void setXingming(String xingming) {
    this.xingming = xingming;
    }

    public String getBanji() {
    return banji;
    }

    public void setBanji(String banji) {
    this.banji = banji;
    }

    public String getKecheng() {
    return kecheng;
    }

    public void setKecheng(String kecheng) {
    this.kecheng = kecheng;
    }

    public String getFenshu() {
    return fenshu;
    }

    public void setFenshu(String fenshu) {
    this.fenshu = fenshu;
    }

    public get(String xuehao2,String a,String b,String c,String d) {
    xuehao=xuehao2;
    xingming=a;
    banji=b;
    kecheng=c;
    fenshu=d;
    }
    }

  • 相关阅读:
    MongoDB的简单操作
    MongoDB下载安装
    enctype="multipart/form-data" form表单提交值为null
    shiro
    json简单介绍
    Sql Server 安装
    MySQL面试常问的查询操作
    关于分页
    Vuex
    Vue基础安装(精华)
  • 原文地址:https://www.cnblogs.com/092e/p/14170024.html
Copyright © 2020-2023  润新知