• web继续练习


    11.27

    今天继续写那个web系统,没遇道什么问题,明年计划继续写这个web系统

    代码部分:

    package dao;

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

    import bean.TestBean;
    import util.DBUtil;

    public class ChangeDao {

    public static TestBean getByName(String name) {
    String sql = "select * from test1205 where name ="+name;
    Connection conn = DBUtil.getConnection();
    Statement state = null;
    ResultSet rs = null;
    TestBean test = new TestBean();
    try {
    state = conn.createStatement();
    rs = state.executeQuery(sql);
    while (rs.next()) {

    String name1 = rs.getString("name");

    test.setName(name1);

    }
    } catch (SQLException e) {
    e.printStackTrace();
    } finally {
    DBUtil.close(rs, state, conn);
    }
    return test;
    }

    public static boolean changeTheName(String name,String name1) {
    Connection conn = DBUtil.getConnection();
    boolean flag = false;

    try {
    String sql ="update test1205 set name = '"+name1+"' where name = '"+name+"'";

    System.out.println(sql);
    PreparedStatement pstmt = conn.prepareStatement(sql);
    int i = pstmt.executeUpdate();
    pstmt.close();
    conn.close();
    if(i>0) {
    flag = true;
    }

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

    return flag;
    }

    }

    package dao;

    import java.sql.Connection;
    import java.sql.SQLException;
    import java.sql.Statement;

    import util.DBUtil;

    public class DeleteDao {

    public static boolean deleteTheName (String name) {
    boolean f = false;
    String sql = "delete from test1205 where name='" + name + "'";
    //select from test1205 where name = '1'
    Connection conn = DBUtil.getConnection();
    Statement state = null;
    int a = 0;

    try {
    state = conn.createStatement();
    a = state.executeUpdate(sql);
    } catch (SQLException e) {
    e.printStackTrace();
    } finally {
    DBUtil.close(state, conn);
    }
    if (a > 0) {
    f = true;
    }
    return f;
    }

    }

    package dao;

    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.ArrayList;
    import java.util.List;

    import bean.TestBean;
    import util.DBUtil;

    public class SelectDao {

    public static List<TestBean> list() {
    String sql = "select * from test1205";
    List<TestBean> test = new ArrayList<>();
    Connection conn = DBUtil.getConnection();
    Statement state = null;
    ResultSet rs = null;
    try {
    state = conn.createStatement();
    rs = state.executeQuery(sql);
    while (rs.next()) {
    TestBean test1 = new TestBean();

    String name = rs.getString("name");

    test1.setName(name);

    test.add(test1);
    }
    } catch (SQLException e) {
    e.printStackTrace();
    } finally {
    DBUtil.close(rs, state, conn);
    }
    return test;
    }

    }

  • 相关阅读:
    css 讲浮动,haslayout,BFC的文章
    css 给inline和inline-block元素设置margin和padding
    css inline元素和inline-block元素之间缝隙产生原因和解决办法
    js 匿名函数立即执行问题
    css 解决图片下小空隙问题
    css BFC布局及用处
    css 单行/多行文字垂直居中问题
    js柯里化
    js 回调函数理解与应用
    js 四种调用模式和this的关系总结
  • 原文地址:https://www.cnblogs.com/092e/p/14170118.html
Copyright © 2020-2023  润新知