600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > Java+Swing+mysql5实现图书管理系统

Java+Swing+mysql5实现图书管理系统

时间:2023-10-23 15:42:01

相关推荐

Java+Swing+mysql5实现图书管理系统

Java+Swing+mysql5实现图书管理系统

一、系统介绍1.系统功能2.环境配置3.数据库4.工程截图 二、系统展示1.登录页1.1登录成功 2.添加图书分类3.管理图书分类4.新增图书5.管理图书6.退出系统6.关于我们 三、部分代码DBConn.javaLoginFrm.javaBook.java 四、其他获取源码

一、系统介绍

1.系统功能

1.登录系统

2.添加图书分类

3.管理图书分类

4.添加图书

5.管理图书

6.退出系统

7.关于我们

2.环境配置

JDK版本:1.8

Mysql:5.7

3.数据库

/*SQLyog Enterprise v12.09 (64 bit)MySQL - 5.7.14 : Database - swing_book**********************************************************************//*!40101 SET NAMES utf8 */;/*!40101 SET SQL_MODE=''*/;/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;CREATE DATABASE /*!32312 IF NOT EXISTS*/`swing_book` /*!40100 DEFAULT CHARACTER SET latin1 */;USE `swing_book`;/*Table structure for table `book` */DROP TABLE IF EXISTS `book`;CREATE TABLE `book` (`id` int(11) NOT NULL AUTO_INCREMENT,`name` varchar(20) DEFAULT '',`author` varchar(255) DEFAULT '',`sex` varchar(255) DEFAULT '',`price` decimal(10,2) DEFAULT '0.00',`booktype_id` int(11) DEFAULT '0',`desc` varchar(255) DEFAULT '',PRIMARY KEY (`id`),KEY `FK_book` (`booktype_id`),CONSTRAINT `FK_book` FOREIGN KEY (`booktype_id`) REFERENCES `booktype` (`id`)) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;/*Data for the table `book` */insert into `book`(`id`,`name`,`author`,`sex`,`price`,`booktype_id`,`desc`) values (1,'C语言','谭浩强','男','50.00',1,'C语言'),(2,'Java程序设计','詹姆斯·高斯林','男','100.00',1,'Java程序设计'),(3,'图形图像处理','何雄飞','男','40.00',2,'图形图像处理'),(4,'图形图像处理技术','张枝军','男','60.00',2,'图形图像处理技术'),(6,'汇编语言','王爽','女','90.00',1,'汇编语言');/*Table structure for table `booktype` */DROP TABLE IF EXISTS `booktype`;CREATE TABLE `booktype` (`id` int(11) NOT NULL AUTO_INCREMENT,`name` varchar(20) DEFAULT '',`desc` varchar(255) DEFAULT '',PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;/*Data for the table `booktype` */insert into `booktype`(`id`,`name`,`desc`) values (1,'计算机类','计算机类'),(2,'图形图像类','图形图像类'),(3,'经济类','经济类');/*Table structure for table `user` */DROP TABLE IF EXISTS `user`;CREATE TABLE `user` (`id` int(11) NOT NULL AUTO_INCREMENT,`username` varchar(20) DEFAULT '',`userpass` varchar(255) DEFAULT '',PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;/*Data for the table `user` */insert into `user`(`id`,`username`,`userpass`) values (1,'admin','123456');/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

4.工程截图

二、系统展示

1.登录页

1.1登录成功

2.添加图书分类

3.管理图书分类

4.新增图书

5.管理图书

6.退出系统

6.关于我们

三、部分代码

DBConn.java

package .util;import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.SQLException;import java.sql.Statement;public class DBConn {private static String driverName = "com.mysql.jdbc.Driver";private static String url = "jdbc:mysql://localhost:3306/swing_book?characterEncoding=utf8";private static String userName = "root";private static String password = "root";private Connection conn;private Statement stmt;public DBConn() {try {Class.forName(driverName);} catch (ClassNotFoundException e) {e.printStackTrace();}}/*** 连接数据库* * @return* @throws SQLException*/public Connection getConnection() throws SQLException {return DriverManager.getConnection(url, userName, password);}/*** 释放资源*/public void close() {try {if (conn != null) {conn.close();}if (stmt != null) {stmt.close();}} catch (SQLException e) {e.printStackTrace();}}}

LoginFrm.java

package .view;import java.awt.EventQueue;import java.awt.Font;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.Connection;import javax.swing.GroupLayout;import javax.swing.GroupLayout.Alignment;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JTextField;import javax.ponentPlacement;import javax.swing.border.EmptyBorder;import .dao.UserDao;import .model.User;import .util.DBConn;import .util.StringUtil;public class LoginFrm extends JFrame {private JPanel contentPane;private JTextField username_txt;private JPasswordField password_txt;private DBConn db=new DBConn();private UserDao userDao=new UserDao();/*** Launch the application.*/public static void main(String[] args) {EventQueue.invokeLater(new Runnable() {public void run() {try {LoginFrm frame = new LoginFrm();frame.setVisible(true);} catch (Exception e) {e.printStackTrace();}}});}/*** Create the frame.*/public LoginFrm() {setResizable(false);setTitle("\u7BA1\u7406\u5458\u767B\u5F55");setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setBounds(100, 100, 450, 300);contentPane = new JPanel();contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));setContentPane(contentPane);JLabel lblNewLabel = new JLabel("\u56FE\u4E66\u7BA1\u7406\u7CFB\u7EDF");lblNewLabel.setFont(new Font("微软雅黑", Font.PLAIN, 24));JLabel lblNewLabel_1 = new JLabel("\u7528\u6237\u540D:");JLabel lblNewLabel_2 = new JLabel("\u5BC6\u7801:");username_txt = new JTextField();username_txt.setColumns(10);password_txt = new JPasswordField();JButton btnNewButton = new JButton("\u767B\u5F55");btnNewButton.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {LoginActionPerformed(e);}});JButton btnNewButton_1 = new JButton("\u91CD\u7F6E");btnNewButton_1.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {ResetActionPerformed(e);}});GroupLayout gl_contentPane = new GroupLayout(contentPane);gl_contentPane.setHorizontalGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING).addGroup(gl_contentPane.createSequentialGroup().addGap(114).addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING).addGroup(gl_contentPane.createSequentialGroup().addComponent(lblNewLabel_2).addPreferredGap(ComponentPlacement.UNRELATED).addComponent(password_txt, 224, 224, 224).addPreferredGap(ComponentPlacement.RELATED)).addGroup(gl_contentPane.createSequentialGroup().addComponent(lblNewLabel_1).addPreferredGap(ComponentPlacement.RELATED).addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING).addComponent(lblNewLabel).addComponent(username_txt, 226, 226, 226)))).addGap(48)).addGroup(Alignment.LEADING, gl_contentPane.createSequentialGroup().addGap(153).addComponent(btnNewButton).addPreferredGap(ComponentPlacement.UNRELATED).addComponent(btnNewButton_1).addContainerGap(157, Short.MAX_VALUE)));gl_contentPane.setVerticalGroup(gl_contentPane.createParallelGroup(Alignment.LEADING).addGroup(gl_contentPane.createSequentialGroup().addGap(50).addComponent(lblNewLabel).addGap(18).addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE).addComponent(lblNewLabel_1).addComponent(username_txt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addGap(18).addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE).addComponent(lblNewLabel_2).addComponent(password_txt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addGap(18).addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE).addComponent(btnNewButton).addComponent(btnNewButton_1)).addContainerGap(60, Short.MAX_VALUE)));contentPane.setLayout(gl_contentPane);this.setLocationRelativeTo(null);}protected void ResetActionPerformed(ActionEvent e) {// TODO Auto-generated method stubthis.username_txt.setText("");this.password_txt.setText("");}protected void LoginActionPerformed(ActionEvent e) {// TODO Auto-generated method stubString username=this.username_txt.getText();String password=new String(this.password_txt.getPassword());if(StringUtil.isEmpty(username)) {JOptionPane.showMessageDialog(null, "用户名不能为空");return;}if(StringUtil.isEmpty(password)) {JOptionPane.showMessageDialog(null, "密码不能为空");return;}User user=new User(username,password);Connection conn=null;try {conn=db.getConnection();User current_user=userDao.login(conn,user);if(current_user!=null) {JOptionPane.showMessageDialog(null, "登录成功");dispose();new MainFrm().setVisible(true);}else {JOptionPane.showMessageDialog(null, "用户名或者密码错误");}} catch (Exception e1) {// TODO Auto-generated catch blocke1.printStackTrace();}}}

Book.java

package .model;public class Book {private int id;private String name;private String author;private String sex;private Float price;private Integer booktype_id;private String booktype_name;private String desc;public Book() {super();}public Book(String name, String author, String sex, Float price, Integer booktype_id, String desc) {super();this.name = name;this.author = author;this.sex = sex;this.price = price;this.booktype_id = booktype_id;this.desc = desc;}public int getId() {return id;}public void setId(int id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getAuthor() {return author;}public void setAuthor(String author) {this.author = author;}public String getSex() {return sex;}public void setSex(String sex) {this.sex = sex;}public Float getPrice() {return price;}public void setPrice(Float price) {this.price = price;}public Integer getBooktype_id() {return booktype_id;}public void setBooktype_id(Integer booktype_id) {this.booktype_id = booktype_id;}public String getBooktype_name() {return booktype_name;}public void setBooktype_name(String booktype_name) {this.booktype_name = booktype_name;}public String getDesc() {return desc;}public void setDesc(String desc) {this.desc = desc;}}

四、其他

获取源码

点击以下链接获取源码,数据库文件在swing_book.sql文件里面。

Java+Swing+Mysql实现图书管理系统源码

Java+Swing+Mysql实现通讯录管理系统源码

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。