关于图书系统的增减

来源:互联网 发布:yum install y 编辑:程序博客网 时间:2024/05/08 19:08
下面实现图书增减的功能实现的源代码,其中用到了String类,和if 条件语句int整型量,   String sqlStr = "insert into books values(?,?,?,?,?,?,?,?)";


        try (Connection con = DBConnection.getConnection();
                PreparedStatement pstmt = con.prepareStatement(sqlStr);) {
            pstmt.setString(1, book.isbn);
            pstmt.setString(3, book.author);
            pstmt.setString(4, book.yizhe);
            pstmt.setFloat(7, book.price);
            pstmt.setInt(6, book.date);
            pstmt.setString(2, book.bookname);
            pstmt.setString(5, book.chubanshe);
            pstmt.setString(8, book.booktype);


            int result = pstmt.executeUpdate();
            if (result > 0) {
                JOptionPane.showMessageDialog(null, "添加成功");
            } else {
                JOptionPane.showMessageDialog(null, "添加失败");
            }


        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }
0 0
原创粉丝点击