• 大小: 5.31MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-10-11
  • 语言: Java
  • 标签: JAVA  MYSQL  GUI  

资源简介

JAVA-最简单的图书管理系统-增删改查-MYSQL-GUI,适合新手~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

资源截图

代码片段和文件信息

package com.cn.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.cn.model.Book;
import com.cn.util.DbUtil;
import com.cn.util.StringUtil;

public class BookDao extends DbUtil {
PreparedStatement ps = null;
Connection conn = null;
ResultSet rs = null;

//添加方法
public int addBook(Book book) {
DbUtil db = new DbUtil();
conn = db.getCon();
String sql = “insert into book (bookid bookname author price other) VALUES (? ? ? ? ?)“;
int num = 0;

try {
ps = conn.prepareStatement(sql);
ps.setString(1 book.getBookId());
ps.setString(2 book.getName());
ps.setString(3 book.getAuthor());
ps.setDouble(4 book.getPrice());
ps.setString(5 book.getOther());

// 执行更新操作
num = ps.executeUpdate();

} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
// 释放资源
super.release(null ps conn);
}

return num;
}

//查询方法
public ArrayList getBook(String bookname){
conn = super.getCon();
       
        ArrayList list = new ArrayList<>();

        Book book;

        try {
            //构造SQL语句
            StringBuffer sql = new StringBuffer(“SELECT * FROM book“);
            
            if (!StringUtil.isNull(bookname)){
             sql.append(“ where bookname like ‘%“ + bookname + “%‘“);
            }

            //创建执行对象
            ps = conn.prepareStatement(new String(sql));

            //执行查询,得到结果集
            rs = ps.executeQuery();

            //对结果集进行遍历
            while (rs.next()) {
                //实例化book对象
             book = new Book();

                //利用set方法对book对象进行赋值
             book.setBookId(rs.getString(“bookid“));
             book.setName(rs.getString(“bookname“));
             book.setAuthor(rs.getString(“author“));
             book.setPrice(rs.getDouble(“price“));
             book.setOther(rs.getString(“other“));

                list.add(book);
            }
        } catch (SQLException e) {
            //异常处理
            e.printStackTrace();
        } finally {
            //释放资源
            super.release(null ps conn);
        }
return list;
}

public static void main(String[] args) {
BookDao bDao = new BookDao();
ArrayList list = bDao.getBook(““);
System.out.println(list.get(0));

}
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2020-07-06 16:23  20200706_gui_demo01\
     文件         917  2020-07-06 16:25  20200706_gui_demo01\.classpath
     文件         733  2020-07-06 11:07  20200706_gui_demo01\.project
     目录           0  2020-07-06 11:07  20200706_gui_demo01\.settings\
     文件         364  2020-07-06 11:07  20200706_gui_demo01\.settings\org.eclipse.jdt.core.prefs
     文件         130  2020-07-06 11:07  20200706_gui_demo01\.settings\org.eclipse.jpt.core.prefs
     文件         167  2020-07-06 11:07  20200706_gui_demo01\.settings\org.eclipse.wst.common.project.facet.core.prefs.xml
     文件         255  2020-07-06 11:07  20200706_gui_demo01\.settings\org.eclipse.wst.common.project.facet.core.xml
     目录           0  2020-07-06 11:07  20200706_gui_demo01\build\
     目录           0  2020-07-09 08:48  20200706_gui_demo01\build\classes\
     目录           0  2020-07-09 08:48  20200706_gui_demo01\build\classes\com\
     目录           0  2020-07-09 08:48  20200706_gui_demo01\build\classes\com\cn\
     目录           0  2020-07-09 08:48  20200706_gui_demo01\build\classes\com\cn\dao\
     文件        3903  2020-07-09 08:48  20200706_gui_demo01\build\classes\com\cn\dao\BookDao.class
     文件        1789  2020-07-09 08:48  20200706_gui_demo01\build\classes\com\cn\dao\UserDao.class
     目录           0  2020-07-09 08:48  20200706_gui_demo01\build\classes\com\cn\model\
     文件        2173  2020-07-09 08:48  20200706_gui_demo01\build\classes\com\cn\model\Book.class
     文件        1061  2020-07-09 08:48  20200706_gui_demo01\build\classes\com\cn\model\User.class
     目录           0  2020-07-09 08:48  20200706_gui_demo01\build\classes\com\cn\util\
     文件        1965  2020-07-09 08:48  20200706_gui_demo01\build\classes\com\cn\util\DbUtil.class
     文件         652  2020-07-09 08:48  20200706_gui_demo01\build\classes\com\cn\util\StringUtil.class
     目录           0  2020-07-09 08:48  20200706_gui_demo01\build\classes\com\java\
     目录           0  2020-07-09 08:48  20200706_gui_demo01\build\classes\com\java\view\
     文件         738  2020-07-09 08:48  20200706_gui_demo01\build\classes\com\java\view\AboutMe$1.class
     文件        2837  2020-07-09 08:48  20200706_gui_demo01\build\classes\com\java\view\AboutMe.class
     文件         738  2020-07-09 08:48  20200706_gui_demo01\build\classes\com\java\view\AddBook$1.class
     文件         678  2020-07-09 08:48  20200706_gui_demo01\build\classes\com\java\view\AddBook$2.class
     文件         678  2020-07-09 08:48  20200706_gui_demo01\build\classes\com\java\view\AddBook$3.class
     文件        6375  2020-07-09 08:48  20200706_gui_demo01\build\classes\com\java\view\AddBook.class
     文件         785  2020-07-09 08:48  20200706_gui_demo01\build\classes\com\java\view\Login$1.class
     文件         722  2020-07-09 08:48  20200706_gui_demo01\build\classes\com\java\view\Login$2.class
............此处省略169个文件信息

评论

共有 条评论