图书管理系统——经典练习项目(Java+Swing+mysql)

图书管理系统(Java+Swing+mysql)

最近跟着网上视频试做了一个入门项目。该项目是一个简单入门项目,代码有点多不方便全部粘贴,不过会贴出重要代码部分,有需要源码的朋友可在文末获取。项目情况大致如下:
在这里插入图片描述

连接数据库登录、为了项目的体验更好加入前判空:

private void loginAction(ActionEvent evt) {
		// TODO Auto-generated method stub
		String username=this.userName.getText();
		String password=new String(this.userPassword.getPassword());
		if(StringUtil.isEmpty(username)) {
			JOptionPane.showMessageDialog(null, "用户名不能为空");
			return;
		}
		if(StringUtil.isEmpty(password)) {
			JOptionPane.showMessageDialog(null, "密码不能为空");
			return;
		}
		User user=new User(username,password);
		Connection con=null;
		try {
			con=dbUtil.getCon();
			User currentuser=userDao.login(con, user);
			if(currentuser!=null) {
				dispose();
				new Main().setVisible(true);;
			}else {
				JOptionPane.showMessageDialog(null, "用户名或密码错误");
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

在这里插入图片描述
用户名是已存在、验证码框得到焦点时判断两次密码是否相同:

/**
	 * 用户名是否存在
	 * @param con
	 * @param name
	 * @return
	 * @throws Exception
	 */
	public boolean isExist(Connection con,String name) throws Exception {
		String sql="select id from user where userName=?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1, name);
		ResultSet rs=pstmt.executeQuery();
		return rs.next();
	}
	/**
		 * 验证码框得到焦点时判断两次密码是否相同
		 */
	Verification1.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent e) {
				Verification1.setText(StringUtil.RegsiterString());
			}

在这里插入图片描述
对图书类别的:增、删(删除前判断类别下是否有图书)、改、查:

	/**
	 * 添加
	 * @param con
	 * @param bookType
	 * @return
	 * @throws Exception
	 */
	public int add(Connection con, BookType bookType) throws Exception {
		String sql = "insert into bookType values(null,?,?)";
		PreparedStatement pstmt = con.prepareStatement(sql);
		pstmt.setString(1, bookType.getBookTypeName());
		pstmt.setString(2, bookType.getBookTypeDesc());
		return pstmt.executeUpdate();
	}
	/**
	 * 删除图书类别
	 * @param con
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public int delete(Connection con,String id) throws Exception {
		String sql="delete from booktype where id=?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1, id);		
		return pstmt.executeUpdate();
	}
	/**
	 * 判断类别下是否有图书
	 * @param con
	 * @param id
	 * @return
	 * @throws Exception
	 */
		public boolean exitBookByBookTypeId(Connection con,String id) throws Exception {
		String sql="select * from book where bookTypeid=?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1,id);
		ResultSet rs=pstmt.executeQuery();
		return rs.next();
	}
	/**
	 * 更新数据类别
	 * @param con
	 * @param bookType
	 * @return
	 * @throws Exception
	 */
	public int updata(Connection con,BookType bookType) throws Exception {
		String sql="update 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();
	}
		/**
	 * 查询图书类别
	 * @param con
	 * @param bookType
	 * @return
	 * @throws Exception 
	 */
	public ResultSet list(Connection con,BookType bookType) throws Exception {
		StringBuffer sb=new StringBuffer("select * from 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();
	}

在这里插入图片描述
对图书类别的:增、删、改、查:其原理与图书类别相似就不再重复贴。
页面布局使用了Swing插件相对较方便。
通过这个项目可以让自己对Mysql的增、删、改、查更熟悉,夯实基础很重要。

源码获取方式,关注菜鸟乐编程,然后回复:源码01图书管理系统
在这里插入图片描述

  • 15
    点赞
  • 111
    收藏
    觉得还不错? 一键收藏
  • 62
    评论
Java语言是一种面向对象的编程语言,拥有良好的跨平台性,同时也是当今最流行的编程语言之一。SwingJava提供的GUI工具包,可以用于创建各种图形用户界面。MySQL是一种现代的关系型数据库管理系统,免费开源,具有高可靠性、高性能、高安全性等特点。图书管理系统是一种常见的信息管理系统,可以用来处理图书借阅、归还、入库、出库等相关业务。 因此,Java Swing MySQL图书管理系统是一个基于Java语言和Swing图形界面技术开发的图书管理系统,它通过与MySQL数据库进行集成,可以实现图书信息的录入、管理、查询和统计等多种功能。系统的主要模块包括读者管理、图书管理、借阅管理、统计分析等。其中读者管理包括读者信息的录入、查找、修改和删除等操作;图书管理包括图书的入库、出库、查询、修改和删除等操作;借阅管理包括读者的借阅、归还、续借等操作;统计分析则包括对图书数据的分析、统计和报表输出。 利用Java Swing MySQL图书管理系统,管理员可以方便地管理图书信息和读者信息,实现自动化借阅和归还,减轻了管理员的工作负担,同时也保证了图书流通的顺畅性。此外,系统还可以为读者提供自助借还书和在线查询等功能,提升了图书馆的服务质量和用户体验。总之,Java Swing MySQL图书管理系统是一个强大而实用的工具,为图书馆的管理工作提供了可靠的支持。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 62
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值