在好例子网,分享、交流、成长!
您当前所在位置:首页Java 开发实例Java语言基础 → 数据库课程设计:图书管理系统(JAVA源码+sql server数据库)

数据库课程设计:图书管理系统(JAVA源码+sql server数据库)

Java语言基础

下载此实例
  • 开发语言:Java
  • 实例大小:1.19M
  • 下载次数:448
  • 浏览次数:4892
  • 发布时间:2019-06-27
  • 实例类别:Java语言基础
  • 发 布 人:crazycode
  • 文件格式:.zip
  • 所需积分:2
 相关标签: 数据库 java 系统 管理 图书

实例介绍

【实例简介】开发工具:MyEclipse、SQL Server 2008,基本的图书管理系统,包含增删改查、java图形界面,数据库技术包含存储过程与触发器。

【调试步骤】

0. 执行数据库脚本 或者附加数据库 以达到让数据库可用的目的

1. 修改源码中的数据库密码 为您本地的密码

2. 输入管理员账号密码admin1/admin1 即可看到如下界面

【实例截图】

from clipboard

from clipboard


from clipboard


from clipboard



读者登陆如下:

from clipboard


from clipboard


from clipboard




from clipboard



from clipboard



【核心代码】


package MainUI;


import java.awt.*;
import java.awt.event.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.swing.*;
import javax.swing.Timer;
 
 
import java.util.*;
 
public class login extends JFrame implements ActionListener, ItemListener {
	Container ct; 
	BackgroundPanel bgp; 
	
    JLabel user = new JLabel("用户名:");
    JLabel password = new JLabel("密    码:");
    JLabel usertype = new JLabel("用户类型:");
    JLabel space = new JLabel("        ");//用来占位
    JButton login = new JButton();
    JButton cancel = new JButton();
     
    ButtonGroup buttongroup = new ButtonGroup();
    JRadioButton mang = new JRadioButton("管理员");
    JRadioButton stu = new JRadioButton("读者");
    
    static JTextField text1 = new JTextField(18);
    JPasswordField text2 = new JPasswordField(18);

    public int a=0,b=0;
    
    
    public static void main(String args[]) {
    	new login();
    }
    
    public login() {
        super("登陆窗口");
        
       // setResizable(false);
        
        bgp=new BackgroundPanel((new ImageIcon("photo//login//login.jpg")).getImage()); //参数是一个Image对象,
        bgp.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 15));
        bgp.setBounds(0,0,300,220);
         
        bgp.add(user);
        bgp.add(text1);
        bgp.add(password);
        bgp.add(text2);
        bgp.add(usertype);
        bgp.add(mang);
        bgp.add(stu);
         
        bgp.add(space);
        
        buttongroup.add(mang);
        buttongroup.add(stu);
        
        login.setIcon(new ImageIcon("photo//login//register.png"));
        login.setBorder(null); 
        cancel.setIcon(new ImageIcon("photo//login//exit.png"));
        cancel.setBorder(null);
        bgp.add(login);
        bgp.add(cancel);
        
        
        ct=this.getContentPane();
        ct.add(bgp);
       
        this.setLayout(null); 
         
        mang.addItemListener(this);//添加事件监听
        stu.addItemListener(this);
        login.addActionListener(this);
        cancel.addActionListener(this);
        
        this.setSize(300,220);  
        this.setLocationRelativeTo(null); 
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
        this.setResizable(false);
        this.setVisible(true); 
        
       // pack();
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                dispose();
                System.exit(0);
            }
        });
    }
 
    public void actionPerformed(ActionEvent e) {//登录按钮
        if (e.getSource() == login) {
        	
        	Connection conn = null;
            Statement stmt = null;
            ResultSet rs = null;
            String url = "jdbc:sqlserver://localhost:1433;DatabaseName=librarydb;";
            String sql = "select * from Admin";
            String sql2 = "select * from Reader";
            String eq = null;
            if(a==1&&b==0)
            {
            	eq = sql;
            }else if(a==0&&b==1)
            {
            	eq=sql2;
            }
            
            try {
                // 连接数据库
            	reminder(text1.getText(),text2.getText());//检查登录的问题
                conn = DriverManager.getConnection(url, "sa", "1@1.com");
                stmt = conn.createStatement();
                rs = stmt.executeQuery(eq);//连接数据库
                while (rs.next()) {
                    String account1 = rs.getString("Admin_id");//账号
                    String password1 = rs.getString("Admin_code");//密码
                    if(account1.equals(text1.getText())&&password1.equals(text2.getText())&&a==1)//管理员
                    {
                    	new MainForm(text1.getText(),true,true);
                    	JOptionPane.showMessageDialog(null, "管理员登录", "登录信息",JOptionPane.WARNING_MESSAGE);
                    	dispose();
                    }                   
                }
                if (rs != null) {rs.close();rs = null;}
                if (stmt != null) {stmt.close();stmt = null;}
                if (conn != null) {conn.close();conn = null;}
        }catch (Exception e1) {
        	try{
        	while (rs.next()) {
                String account2 = rs.getString("Reader_id");//账号
                String password2 = rs.getString("Reader_code");//密码
               if(account2.equals(text1.getText())&&password2.equals(text2.getText())&&b==1)//读者
                {
                	new MainForm(text1.getText(),true,false);
                	JOptionPane.showMessageDialog(null, "读者登录", "登录信息",JOptionPane.WARNING_MESSAGE);
                	dispose();
                }               
            }
        	if (rs != null) {rs.close();rs = null;}
            if (stmt != null) {stmt.close();stmt = null;}
            if (conn != null) {conn.close();conn = null;}
        	}catch(Exception e2){
        		//JOptionPane.showMessageDialog(null, "数据库连接失败,你的账户密码有误", "出现错误",JOptionPane.WARNING_MESSAGE);
        	}
            }
            } else if (e.getSource() == cancel) {//退出按钮
            dispose();
        }
    }
 
	public void itemStateChanged(ItemEvent e) 
    {//三种身份按钮

            if (e.getSource() == mang) {
            	a=1;b=0;
            } else if (e.getSource() == stu) {
            	a=0;b=1;
            }
    } 
    
    public void reminder(String acc,String pwd)
    {	
    	acc=text1.getText();
    	pwd=text2.getText();
    	if(acc.length()==0&&pwd.length()!=0){ShakeFrame();}
    	if(acc.length()!=0&&pwd.length()==0){ShakeFrame();}
    	if(acc.length()==0&&pwd.length()==0){ShakeFrame();}
    	
    }
    
    public void ShakeFrame(){
    	int x = this.getX();
        int y = this.getY();
        for (int i = 0; i < 10; i  ) {
         if ((i & 1) == 0) {
          x  = 3;
          y  = 3;
         } else {
          x -= 3;
          y -= 3;
         }
         this.setLocation(x, y);
         try {
          Thread.sleep(50);
         } catch (InterruptedException e1) {
          e1.printStackTrace();
         }
         }
        }
}


class BackgroundPanel extends JPanel  
{  
    Image im;  
    public BackgroundPanel(Image im)  
    {  
        this.im=im;  
        this.setOpaque(true);                    //设置控件不透明,若是false,那么就是透明
    }  
    //Draw the background again,继承自Jpanle,是Swing控件需要继承实现的方法,而不是AWT中的Paint()
    public void paintComponent(Graphics g)       //绘图类,详情可见博主的Java 下 java-Graphics 
    {  
        super.paintComponents(g);  
        g.drawImage(im,0,0,this.getWidth(),this.getHeight(),this);  //绘制指定图像中当前可用的图像。图像的左上角位于该图形上下文坐标空间的 (x, y)。图像中的透明像素不影响该处已存在的像素

    }  
}


实例下载地址

数据库课程设计:图书管理系统(JAVA源码+sql server数据库)

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

第 1 楼 暮冬浅夏 发表于: 2019-12-30 17:50 53
有修改的具体步骤没,求详细说明

支持(0) 盖楼(回复)

发表评论

(您的评论需要经过审核才能显示)

查看所有1条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警