• 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;
    }

    }

  • 相关阅读:
    hdu 5112 A Curious Matt (水题)
    hdu 5464 Clarke and problem(dp)
    (2)线程优先级、线程安全
    (1)进程与线程
    并发与并行
    (5) 守护线程与线程阻塞
    java线程中断2
    sleep()和wait()的区别
    java线程中断
    java创建线程的三种方式及其对比
  • 原文地址:https://www.cnblogs.com/092e/p/14170118.html
Copyright © 2020-2023  润新知