房屋租赁管理系统主要完成功能为:
1.运行环境: jdk 17;
2.编辑器:IDEA;
3.数据库:MySql 5.7/8.0等版本均可;
因为上传资源限制所以展示了部分功能
package dao;
import model.Admin;
import java.sql.*;
public class HouseDao {
private static String dbClassName = "com.mysql.cj.jdbc.Driver";
private static String dbUrl = "jdbc:mysql://localhost:3306/房屋租赁管理系统?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8"; // 改成自己的端口号这里默认端口号为3306
private static String dbUser = "root"; // 需改成自己数据库的用户名
private static String dbPwd = "123456"; // // 需改成自己数据库的密码
public static Connection conn = null;
// 构造方法,获取连接
public HouseDao() {
try {
if (conn == null) {
Class.forName(dbClassName);
conn = DriverManager.getConnection(dbUrl, dbUser, dbPwd);
}
} catch (Exception e) {
e.printStackTrace();
}
}
// 关闭连接
public static void close() {
try {
if (conn != null) conn.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
conn = null;
}
}
public static void main(String[] args) {
try {
if (HouseDao.conn != null) {
System.out.println("数据库连接成功!");
} else {
System.out.println("数据库连接失败!");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
close(); // 关闭连接
}
}
public static Admin check(String username, String password)
{
Admin Admin = new Admin();
String sql = "select * from 管理员账户 where 用户名 = '" + username + "' and 密码 = '" + password + "'";
try
{
ResultSet rs = HouseDao.executeQuery(sql);
if (rs.next())
{
Admin.setId(rs.getString("id"));
Admin.setName(rs.getString("用户名"));
Admin.setPassword(rs.getString("密码"));
}
else return null;
}
catch (Exception e)
{
e.printStackTrace();
}
HouseDao.close();
return Admin;
}
// 执行查询
public static ResultSet executeQuery(String sql)
{
try
{
if (conn==null) new HouseDao();
return conn.createStatement().executeQuery(sql);
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
}
// 执行更新
public static int executeUpdate(String sql)
{
try
{
if (conn==null) new HouseDao();
return conn.createStatement().executeUpdate(sql);
}
catch (Exception e)
{
e.printStackTrace();
return -1;
}
}
}
package main;
import dao.HouseDao;
import model.Admin;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Login extends JFrame {
private static Admin user = null;
public static void main(String[] args)
{
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e)
{
e.printStackTrace();
}
Login frame = new Login();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public Login() {
initComponents();
}
private void login(ActionEvent e) {
// TODO add your code here
Admin admin = HouseDao.check(username.getText(),password.getText());
if (admin == null)
{
JOptionPane.showMessageDialog(null,"登录失败!");
}
else
{
// System.out.println(Admin.getName());
JOptionPane.showMessageDialog(null, "登录成功!");
user = admin;
new HouseFrame().setVisible(true);
dispose();
}
}
private void cancel(ActionEvent e) {
// TODO add your code here
dispose();
}
private void passwordTFKeyTyped(KeyEvent e) {
// TODO add your code here
if (e.getKeyChar() == '\n')
{
loginButton.doClick();
}
}
代码和数据小编已放置阿里云盘和百度网盘
百度网盘地址:链接:https://pan.baidu.com/s/19Ak24CSBOcs7eMy-q2YaJw?
提取码:6666
阿里云盘地址:阿里云盘分享
阿里云盘快一点,对没有百度网盘会员的小可爱友好一点
这是博主第一次发文章,还多请各位小可爱多多点赞支持,你们的支持是我最大的动力,后续博主也会发布更多的web前端以及Python的源码和小项目,代码有问题或有什么其他运行环境问题都可以随时私信博主或联系博主QQ:1196094293(请写好备注哈)
谢谢各位的支持~~