zoukankan      html  css  js  c++  java
  • mysql增删改查

    public class BookTypeDao {
      增加
    public int bookTypeAdd(Connection con, BookType bookType) throws SQLException{ String sql="insert into t_bookType values(null,?,?)"; PreparedStatement pstmt=con.prepareStatement(sql); pstmt.setString(1, bookType.getBookTypeName()); pstmt.setString(2, bookType.getBookTypeDesc()); return pstmt.executeUpdate(); }
      查找
    public ResultSet bookTypeList(Connection con,BookType bookType) throws SQLException{ StringBuffer sb=new StringBuffer("select * from t_bookType") ; if(StringUtil.isNotEmpty(bookType.getBookTypeName())){ sb.append(" and bookTypeName like '%"+bookType.getBookTypeName()+"%'"); } PreparedStatement pstmt=con.prepareStatement(sb.toString().replaceFirst("and", "where")); return pstmt.executeQuery(); }
      删除
    public int bookTypeDelete(Connection con,String id) throws SQLException{ String sql="delete from t_bookType where id=?"; PreparedStatement pstmt=con.prepareStatement(sql); pstmt.setString(1, id); return pstmt.executeUpdate(); }
      修改
    public int bookTypeModify(Connection con,BookType bookType) throws SQLException{ String sql="update t_bookType set bookTypeName=?,bookTypeDesc=? where id=?"; PreparedStatement pstmt=con.prepareStatement(sql); pstmt.setString(1, bookType.getBookTypeName()); pstmt.setString(2, bookType.getBookTypeDesc()); pstmt.setInt(3, bookType.getId()); return pstmt.executeUpdate(); } }
  • 相关阅读:
    maven项目编译漏掉src/main/java下的xml配置文件
    读《架构探险——从零开始写Java Web框架》
    使用generator自动生成Mybatis映射配置文件
    git项目添加.gitigore文件
    git-bash下, 启动sshd
    git-bash.exe参数
    少估了一分, 还算不错
    python常用库
    Linux下python pip手动安装笔记
    python学习笔记
  • 原文地址:https://www.cnblogs.com/xlwh/p/8592927.html
Copyright © 2011-2022 走看看