基本信息
源码名称:数据库课程设计:图书管理系统(JAVA源码+sql server数据库)
源码大小:1.19M
文件格式:.zip
开发语言:Java
更新时间:2019-06-27
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
开发工具:MyEclipse、SQL Server 2008,基本的图书管理系统,包含增删改查、java图形界面,数据库技术包含存储过程与触发器。
【调试步骤】
0. 执行数据库脚本 或者附加数据库 以达到让数据库可用的目的
1. 修改源码中的数据库密码 为您本地的密码
2. 输入管理员账号密码admin1/admin1 即可看到如下界面
读者登陆如下:
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)。图像中的透明像素不影响该处已存在的像素 } }