Java+Swing+mysql5实现通讯录管理系统
Java+Swing+mysql5实现通讯录管理系统一、系统介绍1.系统功能2.环境配置3.数据库4.工程截图二、系统展示1.登录页1.1登录成功2.主页3.查询联系人4.新增联系人5.修改联系人三、部分代码DBConn.javaLogin.javaAddressBook.java四、其他获取源码一、系统介绍1.系统功能1.登录系统2.查询联系人3.新增联系人4.修改联系人5.删除联系人2.环境配
·
Java+Swing+mysql5实现通讯录管理系统
一、系统介绍
1.系统功能
1.登录系统
2.查询联系人
3.新增联系人
4.修改联系人
5.删除联系人
2.环境配置
JDK版本:1.8
Mysql:5.7
3.数据库
/*
Navicat Premium Data Transfer
Source Server : MySQL
Source Server Type : MySQL
Source Server Version : 80013
Source Host : localhost:3306
Source Schema : swing_address
Target Server Type : MySQL
Target Server Version : 80013
File Encoding : 65001
Date: 10/06/2021 23:56:16
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for my_address_book
-- ----------------------------
DROP TABLE IF EXISTS `my_address_book`;
CREATE TABLE `my_address_book` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
`sex` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
`telephone` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
`mail` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
`birthday` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
`note` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8 COLLATE = utf8_bin ROW_FORMAT = Compact;
-- ----------------------------
-- Records of my_address_book
-- ----------------------------
INSERT INTO `my_address_book` VALUES (2, '杨XX', '男', '18911616917', '1@163.com', '20200107', 'XX');
INSERT INTO `my_address_book` VALUES (3, '222', '女', '22', '22', '22', '22');
INSERT INTO `my_address_book` VALUES (4, '1', '女', '1', '1', '1', '1');
-- ----------------------------
-- Table structure for my_address_login
-- ----------------------------
DROP TABLE IF EXISTS `my_address_login`;
CREATE TABLE `my_address_login` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
`password` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8 COLLATE = utf8_bin ROW_FORMAT = Compact;
-- ----------------------------
-- Records of my_address_login
-- ----------------------------
INSERT INTO `my_address_login` VALUES (1, '1', '1');
SET FOREIGN_KEY_CHECKS = 1;
4.工程截图
二、系统展示
1.登录页
1.1登录成功
2.主页
3.查询联系人
4.新增联系人
5.修改联系人
三、部分代码
DBConn.java
package cn.com.cdp;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
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_address?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 dispose() {
try {
if (conn != null) {
conn.close();
}
if (stmt != null) {
stmt.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
Login.java
package cn.com.cdp;
import java.awt.FlowLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
public class Login {
public static void main(String args[]) {
Login l=new Login();
l.showUI();
}
public void showUI() {
javax.swing.JFrame login=new javax.swing.JFrame();
login.setTitle("登录通讯录");
login.setSize(340,230);
login.setDefaultCloseOperation(3);
login.setLocationRelativeTo(null);
login.setResizable(false);
java.awt.FlowLayout fl=new java.awt.FlowLayout(FlowLayout.CENTER,2,2);
login.setLayout(fl);
JLabel labname=new JLabel();
labname.setText("用户名:");
labname.setPreferredSize(new java.awt.Dimension(60, 60));
login.add(labname);
JTextField textname=new JTextField();
textname.setPreferredSize(new java.awt.Dimension(250, 30));
login.add(textname);
JLabel labpassword=new JLabel();
labpassword.setText("密 码:");
labpassword.setPreferredSize(new java.awt.Dimension(60, 60));
login.add(labpassword);
JPasswordField jp=new JPasswordField();
jp.setPreferredSize(new java.awt.Dimension(250, 30));
login.add(jp);
javax.swing.JButton button=new javax.swing.JButton();
button.setText("登录");
button.setPreferredSize(new java.awt.Dimension(100, 30));
login.add(button);
login.setVisible(true);
button.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
DBConn dbconn = new DBConn();
Statement stmt = null;
ResultSet rs = null;
try {
stmt = dbconn.getConnection().createStatement();
rs = stmt.executeQuery("select * from my_address_login where username='"+textname.getText()+"' and password='"+jp.getText()+"'");
if (rs.next()) {
JOptionPane.showMessageDialog(null, "登录成功!!!");
new Index();
login.dispose();
}else{
JOptionPane.showMessageDialog(null, "用户名或密码不正确!!!");
}
rs.close();
} catch (SQLException e1) {
e1.printStackTrace();
} finally {
try {
if (stmt != null) {
stmt.close();
}
if (rs != null) {
rs.close();
}
} catch (SQLException e1) {
e1.printStackTrace();
}
}
}
});
}
}
AddressBook.java
package cn.com.cdp;
public class AddressBook {
private String id;
private String name;
private String sex;
private String telephone;
private String mail;
private String birthday;
private String note;
public AddressBook() {
super();
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getTelephone() {
return telephone;
}
public void setTelephone(String telephone) {
this.telephone = telephone;
}
public String getMail() {
return mail;
}
public void setMail(String mail) {
this.mail = mail;
}
public String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
}
四、其他
获取源码
点击以下链接获取源码,数据库文件在swing_address.sql文件里面。
Java+Swing+Mysql实现通讯录管理系统源码
更多推荐
已为社区贡献6条内容
所有评论(0)