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(); } }
  • 相关阅读:
    C语言-typedef和#define
    C语言-指针
    C语言-数据结构-结构体
    数据结构笔记
    树的存储结构
    树的基本知识
    关于矩阵
    LaTex
    札记-碎碎念
    一个大神的个人博客 博客桌面风格很棒 二次元
  • 原文地址:https://www.cnblogs.com/xlwh/p/8592927.html
Copyright © 2011-2022 走看看