欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Java实战之用Swing实现通讯录管理系统

程序员文章站 2022-07-08 20:52:46
一、系统介绍1.系统功能 登录系统 查询信息 新增信息 修改信息 删除信息2.环境配置jdk版本:1.8mysql:8.0.133.数据库/* navicat premi...

一、系统介绍

 1.系统功能

  • 登录系统
  • 查询信息
  • 新增信息
  • 修改信息
  • 删除信息

2.环境配置

jdk版本:1.8
mysql:8.0.13

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.工程截图

Java实战之用Swing实现通讯录管理系统

二、系统展示

1.登录页

Java实战之用Swing实现通讯录管理系统

2.主页

Java实战之用Swing实现通讯录管理系统

3.查询信息

Java实战之用Swing实现通讯录管理系统

4.新增信息

Java实战之用Swing实现通讯录管理系统

5.修改信息

Java实战之用Swing实现通讯录管理系统

三、部分代码

dbconn.java

package com.txl;

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.cj.jdbc.driver";
	private static string url = "jdbc:mysql://localhost:3306/swing_address?servertimezone=utc";
	private static string username = "root";
	private static string password = "admin";
	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 com.txl;

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 java.util.vector;

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,5,5);
		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, 40));
		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()) {
						new myaddressbook();
						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();
					}

				}
			}
		});
		
		
	}
}

test.java

package com.txl;

import java.sql.preparedstatement;
import java.sql.sqlexception;

import javax.swing.joptionpane;
import javax.swing.table.defaulttablemodel;
import javax.swing.table.tablecolumn;

public class test {
	public static void main(string[] args) {
		dbconn dbconn = new dbconn();;;;;
		try {
			for(int i =0 ;i<1000000;i++){
				string sql = "insert into student(name, age)values('xxx"+i+"',30)";
				preparedstatement pstmt = dbconn.getconnection().preparestatement(sql);
				system.out.println(sql);
				pstmt.execute(sql);
				pstmt.close();
			}
		} catch (sqlexception e) {
			// todo auto-generated catch block
			e.printstacktrace();
		} finally {
		}
	
	}
}

到此这篇关于java实战之用swing实现通讯录管理系统的文章就介绍到这了,更多相关javaswing实现通讯录管理内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!