77范文网 - 专业文章范例文档资料分享平台

数据库实验报告(7)

来源:网络收集 时间:2018-12-29 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

}

}

}

5.3 java程序实现

GetConnection.java 连接数据库类 Login 主类,main函数 Login_win 登录界面类 xuanke 选课类 shake 删课类

StudentFrame 学生信息类 Teacher 查看教师信息类

注意:程序类的具体代码实现见附页

6. 系统的使用说明及环境配置

学生选课系统提供了学生选课系统。学生通过以自己的学号(如10001)作为用户名和自定义的密码注册、登录系统后进行相应的学生权限范围内的操作。

连接数据库的登录名:root 密码:root.

附录

相关程序代码如下: 1、数据连接: import java.sql.*; import java.awt.*;

import java.awt.event.*;

import javax.swing.Box;

class GetConnection { private static String driver=\ private static String url=\ private static String user=\ private static String password=\ public static Connection getConnection(){ try{ Class.forName(driver); Connection conn=DriverManager.getConnection(url, user, password); return conn; } catch(Exception e){ e.printStackTrace(); return null; } } }

2、登录:

import java.awt.*;

import java.awt.event.*; import java.sql.Connection;

import java.sql.PreparedStatement; import java.sql.ResultSet;

import java.sql.SQLException;

import javax.swing.*;

import javax.swing.border.*; // 该包中提供Box类

public class Login { public static void main(String args[]){ DengLu_JieMian jiemian=new DengLu_JieMian(); } }

//登录界面,使用BoxLayout布局

class DengLu_JieMian extends Frame implements ActionListener { Button button1,button2; TextField text1,text2; String code=null; DengLu_JieMian(){ setTitle(\欢迎进入湘潭大学选课系统\ Box baseBox,boxV1,boxV2,boxV3,boxV4; boxV1=Box.createHorizontalBox(); Label label1=new Label(\选 课 系 统\ //改变label标签中的字体 label1.setFont(new Font(\ boxV1.add(Box.createHorizontalStrut(25)); boxV1.add(label1); boxV2=Box.createHorizontalBox(); boxV2.add(new Label(\学号\ //两个组件之间添加水平距离 boxV2.add(Box.createHorizontalStrut(10)); text1=new TextField(15); boxV2.add(text1); boxV3=Box.createHorizontalBox(); boxV3.add(new Label(\密码\ boxV3.add(Box.createHorizontalStrut(10)); text2=new TextField(15); text2.setEchoChar('*'); boxV3.add(text2); boxV4=Box.createHorizontalBox(); button1=new Button(\登录\ button1.addActionListener(this); button2=new Button(\退出\ button2.addActionListener(this);

boxV4.add(button1); boxV4.add(Box.createHorizontalStrut(3)); boxV4.add(button2); baseBox=Box.createVerticalBox(); baseBox.add(boxV1); baseBox.add(Box.createVerticalStrut(8)); baseBox.add(boxV2); baseBox.add(Box.createVerticalStrut(8)); baseBox.add(boxV3); baseBox.add(Box.createVerticalStrut(8)); baseBox.add(boxV4); addWindowListener(new WindowAdapter() {// 关闭程序时的操作 public void windowClosing(WindowEvent e) { System.exit(0); } }); setLayout(new FlowLayout()); add(baseBox); setBounds(500,300,500,300); setVisible(true); } public void actionPerformed(ActionEvent e) { if(e.getSource()==button1){ if(text1.getText().equals(\ JOptionPane.showMessageDialog(this,\用户名不能不为空\ } else if(text2.getText().equals(\ JOptionPane.showMessageDialog(null, \密码不能为空,请重新填写\ } if(!(text1.getText().equals(\ try{ Connection conn=GetConnection.getConnection(); PreparedStatement sql2=conn.prepareStatement(\DISTINCT password FROM user WHERE s_id=\ ResultSet rs2=sql2.executeQuery(); while(rs2.next()){ code=rs2.getString(1); } } catch(SQLException e1){

System.out.println(e1); } if(text2.getText().equals(code)){ new StudentFrame(text1.getText()); JOptionPane.showMessageDialog(this,\登录成功\ dispose(); } else{ JOptionPane.showMessageDialog(this,\登录失败\ } } } else if(e.getSource()==button2){ //离开程序 System.exit(0); } } }

3、删课:

import java.awt.*;

import java.awt.event.*; import java.sql.*;

import javax.swing.Box;

class shanke extends Frame { Label xuehao,xingming; Checkbox checkbox2[]; Label l1[],l2[],l3[]; Panel panel; Button b1; shanke(String s1,String s2){ super(\删课界面\ xuehao=new Label(s1); xingming=new Label(s2); Panel p1=new Panel(); p1.add(new Label(\学号:\ p1.add(xuehao); p1.add(new Label(\姓名:\ p1.add(xingming); p1.add(new Label(\欢迎进入选课界面\

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库数据库实验报告(7)在线全文阅读。

数据库实验报告(7).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/397548.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: