精华内容
下载资源
问答
  • 数据库作业,采用JAVA语言编写,还有数据库是SQL数据库。。。。代码大全
  • 教学管理系统:数据库Java Web大作业
  • 数据库模拟的ATM取款机 角色有管理员、一般用户 其中管理员管理一般用户 一般用户管理自己账户
  • 2013-2014 学年第二学期大型数据库技术考查报告 课题名称图书管理系统系统 班 级 11 软工 java2 班 学 号 1115115020 姓 名 戴春奇 成 绩 2014 年 5 月 精选文档 1 课题概述 1.1 课题简介 随着社会的发展人们对知识...
  • 此次采购管理系统用 java 语言实现,用MySQL作为后台的数据库进行信息的存储,用SQL语句完成对人员表、设备信息表、供应商信息表、采购信息表的增、删、改、查四个操作。用JDBC驱动实现前台Java与后台SOL数据库的...
  • 数据库大作业,简单的职工管理系统,java 程序,运用mysql数据库,有详细的程序、数据库设计文档,安装说明,可执行文件,源代码。。
  • java编写的数据库大作业,小区物业管理,需要连接MySQL数据库。
  • 使用java编写数据库的底层实现,并对其封装实现注解实体类进行创建表和简单的操作
  • 用到最短路径算法,有详细注释、说明书,用户信息存于数据库
  • java的源码如下图[img=https://img-bbs.csdn.net/upload/201706/06/1496747477_522018.png][/img] 然后我从命令行运行这个程序,在登录的过程中出现错误,如下图[img=...
  • 此为大学数据库大作业的报告以及源代码及打包程序。数据库使用MySQL设计,管理界面采用java编写,附带完整报告。
  • 数据库大作业

    千次阅读 2019-05-30 20:54:00
    sbwy给的灵感,写了一个生死簿.JAVA+SQL https://pan.baidu.com/s/1q8hi2_oRkaBFCR3VvMMMMA 提取码 sv2g 转载于:https://www.cnblogs.com/ZGQblogs/p/10951987.html

    sbwy给的灵感,写了一个生死簿.JAVA+SQL

    https://pan.baidu.com/s/1q8hi2_oRkaBFCR3VvMMMMA

    提取码 sv2g

    转载于:https://www.cnblogs.com/ZGQblogs/p/10951987.html

    展开全文
  • java大作业(扫雷),自己写的一个小游戏,模仿w7系统上自带的扫雷,但是没有数据库,需要的同志自取
  • 数据库大作业总结 android+Java web+mysql

    千次阅读 2016-06-24 15:37:24
    这是我第一次做和网络相关的程序。虽然之前做过app,但是都没有和网络交互,这次算是从零开始。废话不多说,直接上干货。开发工具: android:android studio ...workbench 来管理数据库,个人感觉phpMyadmin用的

    这是我第一次做和网络相关的程序。虽然之前做过app,但是都没有和网络交互,这次算是从零开始。废话不多说,直接上干货。


    开发工具:

    • android:android studio
    • java web:myEclipse(提取密码:ia8f)各种版本,自选合适版本
    • mysql:参考这篇文章进行配置,我尝试了phpMyadmin和mysql
      workbench 来管理数据库,个人感觉phpMyadmin用的较为熟练。
    • 模拟器:genymotion,强烈推荐这个模拟器,速度快,打开android studio创建的模拟器我要开半个小时!(下载genymotion很顺利,但是下载模拟器十分艰难,具体可以参考本人的这篇文章)
    • 服务器:tomcat 7.x 配置方法参考这里

    以上环境如果能配置好,基本成功一半。(学习者一定要有耐心,配置环境花个一周我认为很正常)
    另外要强调的一点是要有充足的内存。本人是macbook pro 8g内存。如果是其它电脑,建议12g以上内存.


    开发流程

    其实可以说,要完成这个开发,你要走通3个helloworld:

    • android 端的helloworld,代表你的模拟器和android sdk配置完成
    • java web的helloworld代表你服务器端配置完成
    • 数据库端的helloworld(就是一些select语句,这里为了工整使用helloworld代表)

    如果以上信息不会,可以参考android hellowrold程序java web helloworld程序

    android端就是平时我们的手机客户端,java web程序放在服务器上,android与java web交互,获取信息,收到android客户端的信息后,java web向数据库请求信息。具体见下面的流程

    接下来描述程序的整体流程
    1. android端发出http请求(Get请求或者Post请求,不理解也没关系)
    2. 服务器端java web程序接受请求。
    3. 服务器端java web程序访问数据库,获得返回结果。
    4. 服务器端java web程序将返回结果传输给客户端。
    5. 客户端得到结果,显示给客户使用。

    这里写图片描述

    以上是最基本的概念,如果读者还没有跑通3个helloworld,请继续配置环境,如果是已经跑通了所有的helloworld但是对android或者java web的程序结构不太清楚可以参考一下文章,如果都已经完成,那么我们就可以开始开发了。

    没有必要完全搞懂,一边做一边学习即可。


    通讯过程工具+关键代码

    到了这一部分,作者认为读者已经了解如何创建android和java web的程序,并且已经有了基本的sql语句的知识(增、删、查、改)。这一部分纷呈两个模块,第一个模块讲述android如何发送请求,第二个模块讲述java web如何接受请求。

    使用的包:

    • gson(将数据打包成json文件格式、将json解析为对象、在android和java web端都可以使用,此包为谷歌工程师开发,必属精品)
    • xutils(此包集结了中国工程师们的智慧,帮助我们极大的简化了网络通讯,代码简化,各种高性能优点)

    part one

    以下是android端的核心代码,发出一个网络请求,收到查询结果。这是一个登录功能,界面就是两个EditText,当点击登录按钮时发送数据,当访问成功,接收返回数据,在responseInfo.result中,将用户信息存储在sharedPreferce中,并记住登录状态。里面用到了xutils的两个功能

    • HttpUtils:
      send函数

      * 参数:方法(Post或者Get)、访问的网址、参数、返回
      
    • ViewUtils:
      帮助我们方便的找到控件
      现在create方法中调用ViewUtils.Inject方法,在定义控件的时候采用注解的写法,就不需要使用findviewbyid了

    SharedPerference是我引入的一个工具类,在后面提供工具类的代码。

    LoginActivity.java

    package com.example.wxc575843.hellotone.start;
    
    import android.content.DialogInterface;
    import android.content.Intent;
    import android.os.Bundle;
    import android.support.v7.app.AppCompatActivity;
    import android.util.Log;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.TextView;
    import android.widget.Toast;
    
    import com.example.wxc575843.hellotone.Practice.PracticeMain;
    import com.example.wxc575843.hellotone.R;
    import com.example.wxc575843.hellotone.utils.SharePreferenceUtils;
    import com.google.gson.Gson;
    import com.lidroid.xutils.HttpUtils;
    import com.lidroid.xutils.ViewUtils;
    import com.lidroid.xutils.exception.HttpException;
    import com.lidroid.xutils.http.RequestParams;
    import com.lidroid.xutils.http.ResponseInfo;
    import com.lidroid.xutils.http.callback.RequestCallBack;
    import com.lidroid.xutils.http.client.HttpRequest;
    import com.lidroid.xutils.view.annotation.ViewInject;
    import com.model.Global;
    import com.model.User;
    
    public class LoginActivity extends AppCompatActivity {
    
        private final String TAG = "LoginActivity";
    
        private String email;
        private String password;
    
        @ViewInject(R.id.login_email)
        EditText etMail;
    
        @ViewInject(R.id.login_password)
        EditText etPassword;
    
        @ViewInject(R.id.btnLogin)
        Button btnLogin;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_login);
            ViewUtils.inject(this);
    
            btnLogin.setOnClickListener(loginLinster);
        }
    
        Button.OnClickListener loginLinster = new Button.OnClickListener() {
            @Override
            public void onClick(View v) {
                email = etMail.getText().toString().trim();
                password = etPassword.getText().toString();
    
                Log.d(TAG+"email",email);
                Log.d(TAG+"password",password);
                if (email.isEmpty() || password.isEmpty()){
                    Toast.makeText(LoginActivity.this,"sth empty",Toast.LENGTH_SHORT).show();
                }else {
                    HttpUtils httpUtils = new HttpUtils();
                    RequestParams requestParams = new RequestParams();
                    requestParams.addBodyParameter("email",email);
                    requestParams.addBodyParameter("password",password);
    
    String url = http://172.29.105.107:8080/HelloToneWebService/servlet/SigninServlet;
                httpUtils.send(HttpRequest.HttpMethod.POST, url, requestParams, new RequestCallBack<String>() {
                        @Override
                        public void onSuccess(ResponseInfo<String> responseInfo) {
                            String rs = responseInfo.result;
                            Log.d(TAG,rs);
                            Gson gson = new Gson();
                            User user = gson.fromJson(rs, User.class);
                            Log.d(TAG,user.getStateCode()+"");
                            if (user.getStateCode()==1){
                                SharePreferenceUtils.putString(LoginActivity.this,"email",user.getEmail());
                                SharePreferenceUtils.putString(LoginActivity.this,"nickname",user.getNickName());
                                SharePreferenceUtils.putString(LoginActivity.this,"gender",user.getGender());
                                SharePreferenceUtils.putString(LoginActivity.this,"country",user.getCountry());
                                SharePreferenceUtils.putString(LoginActivity.this,"chineseLevel",user.getChineseLevel());
                                SharePreferenceUtils.putInt(LoginActivity.this, "level", user.getLevel());
                                SharePreferenceUtils.putString(LoginActivity.this, "headPicture", user.getHeadPicture());
                                SharePreferenceUtils.putInt(LoginActivity.this, "articleNum", user.getArticleNum());
                                SharePreferenceUtils.putInt(LoginActivity.this,"postNum",user.getPostNum());
                                SharePreferenceUtils.putInt(LoginActivity.this,"experience",user.getExperience());
                                SharePreferenceUtils.putString(LoginActivity.this, "password", password);
                                SharePreferenceUtils.putString(LoginActivity.this,"id",user.getId());
    
                                SharePreferenceUtils.putBoolean(LoginActivity.this,"loginState",true);
    
                                Log.d(TAG,user.getChineseLevel());
    
                                Intent intent = new Intent(LoginActivity.this,MainActivity.class);
                                startActivity(intent);
                                finish();
                            } else {
                                Toast.makeText(LoginActivity.this,R.string.login_wrong,Toast.LENGTH_SHORT).show();
                            }
                        }
    
                        @Override
                        public void onFailure(HttpException e, String s) {
                            Toast.makeText(LoginActivity.this,R.string.register_failed_network,Toast.LENGTH_SHORT).show();
                        }
                    });
                }
            }
        };
    }

    SharePreferenceUtils.java

    package com.example.wxc575843.hellotone.utils;
    
    import android.content.Context;
    import android.content.SharedPreferences;
    
    /**
     * 专门访问和设置SharePreference的工具类, 保存和配置一些设置信息
     * 
     * @author Kevin
     * 
     */
    public class SharePreferenceUtils {
    
        private static final String SHARE_PREFS_NAME = "preference";
        private static SharedPreferences mSharedPreferences;
    
        public static void putBoolean(Context ctx, String key, boolean value) {
            if (mSharedPreferences == null) {
                mSharedPreferences = ctx.getSharedPreferences(SHARE_PREFS_NAME,
                        Context.MODE_PRIVATE);
            }
    
            mSharedPreferences.edit().putBoolean(key, value).commit();
        }
    
        public static boolean getBoolean(Context ctx, String key,
                boolean defaultValue) {
            if (mSharedPreferences == null) {
                mSharedPreferences = ctx.getSharedPreferences(SHARE_PREFS_NAME,
                        Context.MODE_PRIVATE);
            }
    
            return mSharedPreferences.getBoolean(key, defaultValue);
        }
    
        public static void putString(Context ctx, String key, String value) {
            if (mSharedPreferences == null) {
                mSharedPreferences = ctx.getSharedPreferences(SHARE_PREFS_NAME,
                        Context.MODE_PRIVATE);
            }
    
            mSharedPreferences.edit().putString(key, value).commit();
        }
    
        public static String getString(Context ctx, String key, String defaultValue) {
            if (mSharedPreferences == null) {
                mSharedPreferences = ctx.getSharedPreferences(SHARE_PREFS_NAME,
                        Context.MODE_PRIVATE);
            }
    
            return mSharedPreferences.getString(key, defaultValue);
        }
    
        public static void putInt(Context ctx, String key, int value){
            if (mSharedPreferences == null) {
                mSharedPreferences = ctx.getSharedPreferences(SHARE_PREFS_NAME,
                        Context.MODE_PRIVATE);
            }
    
            mSharedPreferences.edit().putInt(key,value).commit();
        }
    
        public static int getInt(Context ctx, String key, int defaultValue) {
            if (mSharedPreferences == null) {
                mSharedPreferences = ctx.getSharedPreferences(SHARE_PREFS_NAME,
                        Context.MODE_PRIVATE);
            }
    
            return mSharedPreferences.getInt(key, defaultValue);
        }
    }
    

    part two

    以下时对应的java web端的代码,接收了请求,进入数据库查询,讲返回结果打包成json的形式返回给用户。SigninServlet.java是响应用户请求的后台代码,后面的配置文件和SqlManager代码是连接数据库的工具类

    SigninServlet.java

    package app.hellotone.web.servlet;
    
    import java.io.IOException;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import app.hellotone.web.dao.SigninDao;
    import app.hellotone.web.model.User;
    
    import org.json.simple.JSONObject;
    
    import com.google.gson.Gson;
    
    
    public class SigninServlet extends HttpServlet {
    
        public void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            doPost(request, response);
    
        }
    
    
        public void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
    
            String email = request.getParameter("email");
            String password = request.getParameter("password");
            User user;
            try {
                SigninDao siginDao = new SigninDao();
                user = siginDao.signIn(email, password);
                Gson gson = new Gson();
                response.setContentType("application/json");
                response.setCharacterEncoding("UTF-8");
                response.getWriter().write(gson.toJson(user));
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    
    
    }
    

    SigninDao.java

    package app.hellotone.web.dao;
    
    import java.io.IOException;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    
    import app.hellotone.web.model.User;
    
    public class SigninDao {
        SqlManager manager;
        String sql = "";
        ResultSet rs;
    
        public SigninDao() throws IOException, ClassNotFoundException{
            manager = SqlManager.createInstance();
        }
    
        public User signIn(String username, String password) throws SQLException{
            boolean success = false;
            this.sql = "select * from UserFull where Email=? and Password=?";
            Object[] params = new Object[]{username,password};
            User user = new User();
            manager.connectDB();
            rs=manager.executeQuery(sql, params);
            if(rs.next()) {
                user.setStateCode(1);
                user.setId(Integer.parseInt(rs.getString("ID")));
                user.setNickName(rs.getString("Nickname"));
                user.setEmail(rs.getString("Email"));
                user.setGender(rs.getString("Gender"));
                user.setCountry(rs.getString("Country"));
                user.setLevel(rs.getInt("ULevel"));
                user.setChineseLevel(rs.getString("汉语水平"));
                user.setHeadPicture(rs.getString("头像"));
                user.setArticleNum(rs.getInt("ArticleNum"));
                user.setPostNum(rs.getInt("PostNum"));
                user.setExperience(rs.getInt("Experience"));
            }
            manager.closeDB();
            return user;
        }
    }
    

    Config.propertise

    #Set *.properties default encoding UTF-8
    
    #\u6570\u636e\u5e93\u5e95\u5c42\u64cd\u4f5c\u7c7b\u914d\u7f6e\u6587\u4ef6
    
    #\u6307\u5b9a\u4e3b\u673a\u5730\u5740
    DBhost=localhost
    #\u6307\u5b9a\u7aef\u53e3\u53f7
    DBport=3306
    #\u6307\u5b9a\u8fde\u63a5\u6570\u636e\u5e93
    DBname=HelloTone
    #\u6307\u5b9a\u7528\u6237\u540d
    DBuser=root
    #\u6307\u5b9a\u5bc6\u7801
    DBpassword=123456

    SqlManager.java

    package app.hellotone.web.dao;
    
    /*
     * 数据库操作类,进行数据库底层操作
     * 配置信息在Config.properties文件中
     * Made By:coolszy
     * 2009.07.07
     */
    
    import java.io.IOException;
    import java.sql.CallableStatement;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.PropertyResourceBundle;
    
    public class SqlManager
    {
        private static SqlManager manager = null; // 静态成员变量,支持单态模式
        private PropertyResourceBundle bundle; // 配置资源文件
        private static String jdbcDrive = null; // JDBC驱动类型
        private String DBhost = ""; // 数据库主机地址
        private String DBname = ""; // 数据库名
        private String DBprot = ""; // 数据库端口
        private String DBuser = ""; // 数据库用户名
        private String DBpasswd = ""; // 数据库密码
        private String strcon = null; // 连接字符串
    
        private Connection conn = null; // 连接对象
        private PreparedStatement pstm = null;
        private CallableStatement cstm = null;
    
        /**
         * 私有构造函数,不可实例化
         * 
         * @throws IOException
         */
        private SqlManager() throws IOException
        {
            // 读取配置文件
            bundle = new PropertyResourceBundle(SqlManager.class
                    .getResourceAsStream("Config.properties"));
            this.DBhost = getString("DBhost"); // 读取主机名
            this.DBname = getString("DBname"); // 读取用户名
            this.DBprot = getString("DBport"); // 读取端口
            this.DBuser = getString("DBuser"); // 读取用户
            this.DBpasswd = getString("DBpassword"); // 读取密码
            // 设置mysql数据库的驱动程序和连接字符
            jdbcDrive = "com.mysql.jdbc.Driver";
            strcon = "jdbc:mysql://" + DBhost + ":" + DBprot + "/" + DBname;
        }
    
        /**
         * 读取配置文件中的值
         * 
         * @param key
         *            配置文件的key
         * @return key对应的值
         */
        private String getString(String key)
        {
            return this.bundle.getString(key);
        }
    
        /**
         * 单态模式获取实例
         * 
         * @return SqlManager对象
         * @throws IOException
         * @throws ClassNotFoundException 
         */
        public static SqlManager createInstance() throws IOException, ClassNotFoundException
        {
            if (manager == null)
            {
                manager = new SqlManager();
                manager.initDB();
            }
            return manager;
        }
    
        /**
         * 初始化连接参数,由指定的DBType生成
         * 
         * @throws ClassNotFoundException
         */
        public void initDB() throws ClassNotFoundException
        {
            Class.forName(jdbcDrive);
        }
    
        /**
         * 连接数据库
         * 
         * @throws SQLException
         */
        public void connectDB() throws SQLException
        {
            conn = DriverManager.getConnection(strcon, DBuser, DBpasswd); // 获取连接
            conn.setAutoCommit(false); // 设置自动提交为false
        }
    
        /**
         * 断开数据库
         * 
         * @throws SQLException
         */
        public void closeDB() throws SQLException
        {
            if (pstm != null)
            {
                pstm.close();
            }
            if (cstm != null)
            {
                cstm.close();
            }
            if (conn != null)
            {
                conn.close();
            }
        }
    
        /**
         * 设置PrepareStatement对象中Sql语句中的参数
         * 
         * @param sql
         *            sql语句
         * @param params
         *            参数列表
         * @throws SQLException
         */
        private void setPrepareStatementParams(String sql, Object[] params)
                throws SQLException
        {
            pstm = conn.prepareStatement(sql); // 获取对象
            if (params != null)
            {
                for (int i = 0; i < params.length; i++) // 遍历参数列表填充参数
                {
                    pstm.setObject(i + 1, params[i]);
                }
            }
        }
    
        /**
         * 执行查询
         * 
         * @param sql
         *            sql语句
         * @param params
         *            参数列表
         * @return 返回ResultSet类型的查询结果
         * @throws SQLException
         */
        public ResultSet executeQuery(String sql, Object[] params)
                throws SQLException
        { // 执行查询数据库接口
            ResultSet rs = null;
            manager.setPrepareStatementParams(sql, params); // 填充参数
            rs = pstm.executeQuery(); // 执行查询操作
            return rs;
        }
    
        /**
         * 更新数据库操作
         * 
         * @param sql
         *            sql语句
         * @param params
         *            参数列表
         * @return 执行操作的结果
         * @throws SQLException
         */
        public boolean executeUpdate(String sql, Object[] params)
                throws SQLException // 执行无返回数据的数据查询,返回值是被改变的书库的数据库项数
        {
            boolean result = false;
            manager.setPrepareStatementParams(sql, params); // 填充参数
            pstm.executeUpdate(); // 执行更新
            manager.commitChange();
            result = true;
            return result;
        }
    
        /**
         * 提交信息到数据库
         * 
         * @throws SQLException
         */
        private void commitChange() throws SQLException
        {
            conn.commit();
        }
    }
    

    到此为止,我们已经完成了总体的交互过程,希望大家能够有所收获,如果还有不明白的,活着我没有讲清楚的地方欢迎在下面提问,我看到会尽快回答。

    展开全文
  • 此为大学数据库大作业的报告以及源代码及打包程序。数据库使用MySQL设计,管理界面采用java编写,附带完整报告。
  • 数据库大作业,是一个用java写的带有漂亮界面的图书销售系统
  • 本系统包含完整文档一份+源...可以作为java、软件开发和数据库相关课程的大作业 本系统功能相对而言不会很复杂,但是作为大作业足够;系统包含:注册、登陆、添加水果、水果分类、修改水果、查询、删除、分类管理等等
  • 通过这个实验回顾数据库这门课程的基本内容,深化自己的理解,掌握高级语言对数据库操作的方法。 二、总体功能设计与ER图 这次的实验是使用Java+ SQL server 完成的。 2.1 总体的功能设计 2.2 ER 图: 2.3 流程图 ...

    一、实验目的

    通过这个实验回顾数据库这门课程的基本内容,深化自己的理解,掌握高级语言对数据库操作的方法。

    二、总体功能设计与ER图

    这次的实验是使用Java+ SQL server 完成的。
    2.1 总体的功能设计

    在这里插入图片描述
    2.2 ER 图
    在这里插入图片描述
    2.3 流程图
    在这里插入图片描述
    2.4 基本表
    (1)SC 表记录学生的选课信息
    在这里插入图片描述
    (2) Course记录课程信息
    在这里插入图片描述
    (3)Student记录学生的基本信息
    在这里插入图片描述
    (4)账户密码记录用户名以及密码
    在这里插入图片描述
    (5)登录信息记录用户登录的时间
    在这里插入图片描述

    三、T-sql 代码

    (1)

    create table Student(
    Sno char(9) primary key,
    Sname char(9),
    Sage smallint,
    )
    ---创建Student表
    create table Course(
    Cno char(9) primary key,
    Cname char(9) ,
    Grade smallint  
    )
    --创建Course表
    create table SC (
    Sno char(9),
    Cno char(9),
    Grade smallint,
    primary key (Sno,Cno)
    )
    alter table SC add constraint from_stu_sc foreign key (Sno) references Student (Sno) on delete cascade
    alter table Sc add constraint from_course_sc foreign key(Cno) references Course(Cno) on delete cascade
    --创建SC并且实现级联删除
    

    (2)
    在sql server 中创建存储过程

    
    if exists(select * from sys.objects where name='pro_tran')
     drop procedure pro_tran
      create procedure pro_tran 
      @Sno char(9)
      as 
    
      begin 
    select SC.Sno, Course.Cno ,Course.Cname
    from   SC ,Course
    where SC.Sno=@Sno and SC.Cno=Course.Cno
     end
    

    在学生模块中会用到
    (3)
    创建触发器,当管理员教师insert或者是update课程的学分时候,如果大于4会自动修改为4。

    create trigger Check_Course_grade
     on Course
      for insert ,update
      as
      declare @num smallint,
         @cno char(9),
    	 @cname char(9)
      select @num= Grade from inserted
      select @cno=Cno from inserted
      select @cname= Cname from inserted
     begin
      if(@num>4)
      if(exists( select * from Course where Cno=@cno))
      update Course set Grade =4
      if not exists(select * from Course where Cno=@cno)
      insert into Course values(@cno,@cname,@num)
      end 
    

    (4)创建登录密码表

    create table (
    account char(9) primary key,
    password char(40) ,
    image image,
    )
    

    (5)创建登录信息表

    create table login_account(
    account char(9),
    login_time datetime,
    )
    

    四、 Java代码

    1、准备工作
    (1) 因为将会使用Jtable组件,并且是不能编辑的,因此需要重写DefaultTableModel 这个类为MyDefaultTable。

    (2)Md5 加密算法:作为一个类,因为不只有一个模块用到这个类

    import java.io.UnsupportedEncodingException;
    import java.security.MessageDigest;
    import java.security.NoSuchAlgorithmException;
    import java.text.SimpleDateFormat;
    import java.util.Base64;
    import java.util.Date;
    public class Md5  {
        public String getMd5_String(String a){
        //重点就是这个方法,返回加密后的密码
            String str = null;
            try{
                MessageDigest md=MessageDigest.getInstance("md5");
                byte[] bytes = md.digest(a.getBytes("UTF-8"));
                //得到了一个字节 计算摘要
                // a-z A-Z 0-9 / * 表示生成的string
                 str= Base64.getEncoder().encodeToString(bytes);
    
            }catch (NoSuchAlgorithmException e){
                e.printStackTrace();
            }
            catch (UnsupportedEncodingException e){
                e.printStackTrace();
                System.out.println("编码不支持");
            }
            return str;
        }
    }
    

    (3)验证码组件 因为都是鼠标点击可以更换验证码,需要注册一下监听器。

    
    public class validCode  extends JComponent implements MouseListener {
     private int width,height =40;
       private String code;
       private int codeLength = 4;
       private Random random = new Random();
       public validCode() {
          this.width = this.codeLength * 16 + (this.codeLength - 1) * 10;
          this.setPreferredSize(new Dimension(width, height));
          this.setSize(width, height);
          this.addMouseListener(this);
          //提示信息
          setToolTipText("看不清楚,换一个!");
       }
       public int getCodeLength() {
          return this.codeLength;
       }
       /*
       设置验证码文字的长度
       */
       public void setCodeLength(int codeLength) {
          if(codeLength < 4) {
             this.codeLength = 4;
          } else {
             this.codeLength = codeLength;
          }
       }
       public String getCode() {
          return code;
       }
       /*
           产生随机的颜色
       */
       public Color getRandColor(int min, int max) {
          if (min > 255)
             min = 255;
          if (max > 255)
             max = 255;
          int red = random.nextInt(max - min) + min;
          int green = random.nextInt(max - min) + min;
          int blue = random.nextInt(max - min) + min;
          return new Color(red, green, blue);
       }
       /*
           设置验证码具体的字母是什么
       */
       protected String generateCode() {
          char[] codes = new char[this.codeLength];
          for (int i = 0, len = codes.length; i < len; i++) {
             if (random.nextBoolean()) {
                codes[i] = (char) (random.nextInt(26) + 65);
             } else {
                codes[i] = (char) (random.nextInt(26) + 97);
             }
          }
          this.code = new String(codes);
          return this.code;
       }
       //核心部分 
       @Override
       protected void paintComponent(Graphics g) {
          super.paintComponent(g);
          if(this.code == null || this.code.length() != this.codeLength) {
             this.code = generateCode();
          }
          this.width = this.codeLength * 16 + (this.codeLength - 1) * 10;
          super.setSize(width, height);
          super.setPreferredSize(new Dimension(width, height));
          Font mFont = new Font("Arial", Font.BOLD | Font.ITALIC, 25);
          g.setFont(mFont);
          //绘制出验证码的背景的矩形轮廓
          Graphics2D g2d = (Graphics2D) g;
          g2d.setColor(getRandColor(200, 250));
          g2d.fillRect(0, 0, width, height);
          g2d.setColor(getRandColor(180, 200));
          g2d.drawRect(0, 0, width - 1, height - 1);
          //绘制出验证码背景的线
          int i = 0, len = 150;
          for (; i < len; i++) {
             int x = random.nextInt(width - 1);
             int y = random.nextInt(height - 1);
             int x1 = random.nextInt(width - 10) + 10;
             int y1 = random.nextInt(height - 4) + 4;
             g2d.setColor(getRandColor(180, 200));
             g2d.drawLine(x, y, x1, y1);
          }
          //绘制出验证码的具体字母
          i = 0; len = this.codeLength;
          FontMetrics fm = g2d.getFontMetrics();
          int base = (height - fm.getHeight())/2 + fm.getAscent();
          for(;i<len;i++) {
             int b = random.nextBoolean() ? 1 : -1;
             g2d.rotate(random.nextInt(10)*0.01*b);
             g2d.setColor(getRandColor(20, 130));
             g2d.drawString(code.charAt(i)+"", 16 * i + 10, base);
          }
       }
       public void nextCode(){
          this.generateCode();
          repaint();
       }
        @Override
        public void mouseClicked(MouseEvent mouseEvent) {
          this.nextCode();
        }
        @Override
        public void mousePressed(MouseEvent mouseEvent) {
        }
        @Override
        public void mouseReleased(MouseEvent mouseEvent) {
        }
        @Override
        public void mouseEntered(MouseEvent mouseEvent) {
        }
        @Override
        public void mouseExited(MouseEvent mouseEvent) {
        }
    }
    验证码组件是利用random产生随机数,进而产生验证码
    
    

    (4)自定义Test类 连接数据库,内置基本的方法,例如增删改查基本操作,其他的类直接调用函数即可。

    public class Test {
     
        public CallableStatement callableStatement=null;
       public Connection ct=null;
        public PreparedStatement ps=null;
         public ResultSet rs=null;
     public Vector<String> con,sno,Cname;
    // 只是在Student页面用到的
    public  Test(){
       //释放的时候容易释放
        this.con=new Vector<String>(); this.sno= new Vector<>(); this.Cname=new Vector<>();
    }
    //select 函数 这个函数的参数是tag ,目标表
    public void select (String tag){
        this.get_sql_connection();
        try{
            this.vector_free();
            this.ps=this.ct.prepareStatement("select * from "+tag);
            this.rs=this.ps.executeQuery();
            
            while(this.rs.next()) {
                this.con.add(rs.getString(1));
                this.sno.add(rs.getString(2));
                this.Cname.add(rs.getString(3));
            }
            System.out.println("数据成功加入");
        }
        catch (Exception e){
            e.printStackTrace();
        }
        finally {
            this.close();
        }
    }
    //释放 vector 的资源
    public  void vector_free(){   // 
       this.con.clear();
       this.Cname.clear();this.sno.clear();
    }
    //连接数据库
    public void get_sql_connection(){
        String  url="jdbc:sqlserver://localhost;
        databaseName=数据库名;user=用户名; password=密码";
        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            this.ct=DriverManager.getConnection(url);
            System.out.println("数据库连接成功");
        }
        catch(Exception e){
            e.printStackTrace();
        }
    }
    // 学生插入 SC 表信息 
        public void insert_SC_by_Stu (String a, String b) throws SQLException {
                this.get_sql_connection();
                this.ps=this.ct.prepareStatement("use [Stu1] insert into  SC (Sno,Cno,Grade) values(?,?,?)");
                this.ps.setString(1,a); this.ps.setString(2,b); this.ps.setString(3,null);
                int i=ps.executeUpdate();
                System.out.println("数据成功加入"+i+"行");
                this.close();
        }
    //教师插入SC
    public void insert_SC_by_tea(String a,String b,String c) throws SQLException {
            this.get_sql_connection();
            this.ps=this.ct.prepareStatement("use [Stu1] insert into SC (Sno,Cno,Grade) values(?,?,?)");
            Integer num=Integer.parseInt(c);
            this.ps.setString(1,a); this.ps.setString(2,b); this.ps.setInt(3,num);
            int i=ps.executeUpdate();
            System.out.println("数据成功加入"+i+"行");
            this.close();
    }
    //教师插入,Course
    public void insert_by_tea(String a,String b,String c,String tag) throws SQLException {
        this.get_sql_connection();
            this.ps=this.ct.prepareStatement("use [Stu1] insert into "+tag+" values(?,?,?) ");
            Integer num=Integer.parseInt(c);
            this.ps.setString(1,a); this.ps.setString(2,b); this.ps.setInt(3,num);
            int i=ps.executeUpdate();
            System.out.println("数据成功加入"+i+"行");
            this.close();
    }
    //删除 Student
    public  int delete ( String a) throws SQLException {
        //这个是按照主码删除元组
        this.get_sql_connection();
            String sql ="delete from Student where Sno=?";
            this.ps=this.ct.prepareStatement(sql);
            this.ps.setString(1,a);
           int i= ps.executeUpdate();
           System.out.println(i+"行 修改");
            this.close();
            return i;
    }//删除SC
        public  int  delete_SC ( String a,String b) throws SQLException {
            //这个是按照主码删除元组
            this.get_sql_connection();
                String sql ="delete from SC  where Sno=? and Cno=?";
                this.ps=this.ct.prepareStatement(sql);
                this.ps.setString(1,a); this.ps.setString(2,b);
                int i= ps.executeUpdate();
                System.out.println(i+"行 修改");
                this.close();
              return i;
    }
    //删除Course时候需要参数较多
        public  int  delete_Course( String a) throws Exception {
            //这个是按照主码删除元组
                this.get_sql_connection();
                String sql ="delete from Course where Cno=?" ;
                this.ps=this.ct.prepareStatement(sql);
                this.ps.setString(1,a);
                int i= ps.executeUpdate();
                System.out.println(i+"行 修改");
                this.close();
       return i;
    }
    //创建表
    public  void create_table() throws Exception {
        this.get_sql_connection();
      String sql= "create table Stu_rt ( Sno char(9) not null, Cno char(4) not null , Grade smallint , primary key (Sno,Cno) )";
    
         this.ps=this.ct.prepareStatement(sql);
         this.ps.executeUpdate();
         System.out.println("ok!!");
      System.out.println("sorry !! data is error!!");
         this.close();
    }
    //教师更新 Student
      public int update_sc_by_tea (String a,String b,String c) throws  Exception{
         int i;
        this.get_sql_connection();
            int  num=Integer.parseInt(c);
            String sql ="update  SC set Grade= ?  where Sno =? and Cno=?" ;
            this.ps=this.ct.prepareStatement(sql);
            this.ps.setString(3,b);
            this.ps.setInt(1,num);
            this.ps.setString(2,a);
             i=this.ps.executeUpdate();
         System.out.println(i+"行 update");
            this.close();
     return i;
    }
    //  更新Student
    public int  update_Student_tea(String a,String b,String c) throws Exception {
         int i;
        this.get_sql_connection();
            int  num=Integer.parseInt(c);
            String sql ="update  Student set  Sname=? ,Sage =? where Sno =? " ;
            this.ps=this.ct.prepareStatement(sql);
            this.ps.setString(3,a);
            this.ps.setInt(2,num);
            this.ps.setString(1,b);
             i=this.ps.executeUpdate();
            System.out.println(i+"行 update");
            this.close();
    return i;
    }
    // 更新 Course
        public int  update_Course_tea(String a,String b,String c) throws Exception {
        int i;
        this.get_sql_connection();
           int num=Integer.parseInt(c);
            String sql= "update Course set Cname=?, Grade=? where Cno=?";
           this.ps=this.ct.prepareStatement(sql);
           this.ps.setString(3,a);
           this.ps.setInt(2,num);
           this.ps.setString(1,b);
            i=this.ps.executeUpdate();
           System.out.println(i+"行 update");
           this.close();
    return  i;
    }
    // 存储过程
    public void call_produce(String sql) throws SQLException {
        String Sno,Cname,Sage;
        this.get_sql_connection();
            //尝试做
            this.callableStatement=  this.ct.prepareCall("{call pro_tran1}");
             this. callableStatement.registerOutParameter(1, Types.SMALLINT);
            this.callableStatement.setString(2,"1");
             this.callableStatement.execute();
            System.out.println("是最大值"+this.callableStatement.getInt(1));
            this.close();
    }
    //最后的方法一定要运行 ,释放
    public void close(){
        try {
            if(this.rs != null) this.rs.close();
            if(this.ps != null)this.ps.close();
            if(this.ct != null)this.ct.close();
            if(this.callableStatement!=null) this.callableStatement.close();
            System.out.println("数据库已经关闭");
        }catch(Exception e) {
        }
    }
    }
    

    Test 是整个程序的核心内容,而Test的最重要的部分可以由以下代码代替:

     this.get_sql_connection();
     this.ps=this.ct.prepareStatement(sql);
    sql 指的是T-sql 语句
    
    
    

    该类的大多数方法是抛出异常而不是直接处理异常,因为Test将作为属性放在别的类中,在保证数据库连接正确的情况下,如果出现错误,那么一定是参数的错误,根据不同类的不同特性,可以做出相应的处理异常动作,比如说“改”这个功能,可能这个类中需要一个JOptionPane的提示,而别的类不需要。
    在update ,delete 功能的函数中是有返回值的 i=this.ps.executeUpdate(); return i; 这个返回值是检验被执行动作的元组是否在基本表中存在的依据。 不存在就是0 ,存在是1 。

    (5)将表格组件设置为透明 ,这里给出一个实例

    • 别的组件都较为简单,表格是最为麻烦的。
    • 这个实例也是设置背景图片的例子
    
    public class Touming  extends JFrame {
        private JTable jTable;
        private JScrollPane jScrollPane;
        private MyDefaultTable table ;
        private  ImageIcon img;
        private  JLabel jl1;
        private DefaultTableCellRenderer renderer;
        public Touming(){
            super("TEST");
            this.renderer= new DefaultTableCellRenderer();
            this.renderer.setOpaque(false);
            this.img= new ImageIcon(getClass().getResource("/photo/13.jpg"));//导入图片
            this.jl1= new JLabel(this.img);
            this.jl1.setBounds(0,0,1000,700);
            String []str={"a","b","c"};
            this.table= new MyDefaultTable(str,22);
            this.jTable= new JTable(this.table);
            this.jScrollPane= new JScrollPane(this.jTable);
            //添加组件
            this.getLayeredPane().add(this.jl1, new Integer(Integer.MIN_VALUE));
            ((JPanel)this.getContentPane()).setOpaque(false);
            for(int i=0;i<=2;i++){
                this.jTable.getColumn(str[i]).setCellRenderer(this.renderer);
            }
            this.jScrollPane.setOpaque(false);
            this.jTable.setOpaque(false);
            this.jScrollPane.getViewport().setOpaque(false);
            this.getContentPane().add(this.jScrollPane);
            this.setSize(1000,700);
            this.setDefaultCloseOperation(Windows.EXIT_ON_CLOSE);
            this.setResizable(false);
            this.setLocationRelativeTo(null);
            this.setVisible(true);
        }
        public static void main(String[] args) {
            new Touming();
        }
    }
    

    2、登录页面
    (1)这个页面较为简单,由按钮,提示框,输入框组成,在JTextField中得到account 以及密码 ,首先是由正则表达式根据用户名的长度判断是教师还是学生,教师为6位,学生为4位,判断之后与数据库中的account_password 表进行比较,正确的话可以分别进入不同的页面。main方法在这个类中。
    (2)具体代码:

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.sql.SQLException;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.regex.*;
    
    public class Login_in  extends JFrame implements ActionListener {
        //组件
        public Test test;
        private Md5 md5;
        public JLabel account;
        private  JPanel jPanel;
        public TableText tableText;
        public JLabel password;
        public JButton button_login_in;
        public JTextField jt_account;
        public JPasswordField jt_password;
        private JButton jb_register; private  Register register;
        public JLabel jl1;
        public ImageIcon img;
        protected Windows windows = null;
        public Login_in() {
            super("选课管理模拟系统");
            this.test = new Test();
            //Test 类是连接数据库的类,由一些基本增删改查方法。
            this.md5 = new Md5();
            // md5 是自己根据MD5算法写的加密密码的类
            this.account = new JLabel("输入用户名"); this.account.setOpaque(false);
            this.password = new JLabel("输入密码"); this.password.setOpaque(false);
            this.button_login_in = new JButton("登录"); this.button_login_in.setOpaque(false);
            this.jb_register=new JButton("注册"); this.jb_register.setOpaque(false);
            //设置背景图片
            this.img= new ImageIcon(getClass().getResource("/photo/6.png"));//导入图片
            this.jl1= new JLabel(this.img);
            this.jl1.setBounds(0,0,this.img.getIconWidth(),this.img.getIconHeight());
             this.jPanel= new JPanel();
             this.jPanel.setOpaque(false);
            this.button_login_in.addActionListener(this);
            this.jt_account = new JTextField(10); this.jt_account.setOpaque(false);
            this.jt_password = new JPasswordField(10); this.jt_password.setOpaque(false);
            //设置页面布局
            this.setSize(this.img.getIconWidth(), this.img.getIconHeight());
            this.getLayeredPane().add(this.jl1, new Integer(Integer.MIN_VALUE));
            //添加背景图片
            ((JPanel)this.getContentPane()).setOpaque(false);
            this.getContentPane().setLayout(null);
            //添加组件
            this.account.setBounds(this.img.getIconHeight()/4,this.img.getIconWidth()/3-80,100,30);
            this.jt_account.setBounds(this.img.getIconHeight()/4+110,this.img.getIconWidth()/3-80,150,30);
            this.password.setBounds(this.img.getIconHeight()/4,this.img.getIconWidth()/3-30,100,30);
            this.jt_password.setBounds(this.img.getIconHeight()/4+110,this.img.getIconWidth()/3-30,150,30);
            this.button_login_in.setBounds(this.img.getIconHeight()/4+20,this.img.getIconWidth()/3+30,80,35);
            this.jb_register.setBounds(this.img.getIconHeight()/4+160,this.img.getIconWidth()/3+30,80,35);
            this.jb_register.setContentAreaFilled(false); this.button_login_in.setContentAreaFilled(false);
            this.jb_register.addActionListener(this);
            this.setLocationRelativeTo(null);
            this.getContentPane().add(this.account);this.getContentPane().add(this.jt_account);this.getContentPane().add(this.password);
            this.getContentPane().add(this.jt_password); this.getContentPane().add(this.button_login_in);this.getContentPane().add(this.jb_register);
            this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            this.setResizable(false);//不能改变大小
            this.setVisible(true);
        }
        //向数据库中login_account 登录时间信息
        public void Login_time(){
            Date date = new Date();
            SimpleDateFormat dateformat= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            this.test.get_sql_connection();
            //连接数据库
            try{
            
                String sql ="insert into login_account values(?,?)";
                this.test.ps=this.test.ct.prepareStatement(sql);
                this.test.ps.setString(1,this.jt_account.getText());
                this.test.ps.setString(2,dateformat.format(date));
                this.test.ps.executeUpdate();
            }catch (Exception e){
                e.printStackTrace();
            }finally {
                this.test.close();
                //关闭连接
            }
        }
        public static void main(String[] args) {
            new Login_in();
        }
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            //如果是登录
                String a;
                boolean flag = false;
                String b;
                String result = null;
                String str = null;
                if (actionEvent.getSource().equals(this.button_login_in)) {
                    a = this.jt_account.getText();
                    b = new String(this.jt_password.getPassword());
                   //正则表达式
                    Pattern p_account = Pattern.compile("^[A-Za-z0-9]{6}$");
                    //
                    Pattern p_account_student = Pattern.compile("^[A-Za-z0-9]{4}$");
                    Matcher m_account = p_account.matcher(a);
                    Matcher m_accout_student = p_account_student.matcher(a);
                    if (m_account.find()) { //教师匹配的话
                        try {
                        //将输入的密码与account_password中的密码比较
                  
                            this.test.get_sql_connection();
                            this.test.ps = this.test.ct.prepareStatement("select  password  from account_password  where account=? and password=?");
                            this.test.ps.setString(1, a);
                            this.test.ps.setString(2, this.md5.getMd5_String(b));
                            this.test.rs = this.test.ps.executeQuery();
                            flag = this.test.rs.next();
                        } catch (Exception e) {
                        } finally {
                            this.test.close();
                        }
                        if (flag == true) {
                            this.Login_time();
                            if (this.windows == null) {
                                this.windows = new Windows(this, this.test);
                                //传引用
                            }
                            this.windows.setVisible(true);
                            this.setVisible(false);
                            System.out.println("ok is login ");
                        } else {
                            JOptionPane.showMessageDialog(this, "密码或者用户名不正确");
                        }
                    }  //教师匹配的话
                    
                    //学生匹配的话
                    else if (m_accout_student.find()) {
                        try {
                            this.test.get_sql_connection();
                            this.test.ps = this.test.ct.prepareStatement("select  password  from account_password  where account=? and password=?");
                            this.test.ps.setString(1, a);
                            this.test.ps.setString(2, this.md5.getMd5_String(b));
                            this.test.rs = this.test.ps.executeQuery();
                            flag = this.test.rs.next();
                        } catch (Exception e) {
                        } finally {
                            this.test.close();
                        }
                        if (flag == true) {
                        // 如果用户名以及密码正确的话
                            this.Login_time();
                            if (this.tableText == null) {
                                this.tableText = new TableText(this,this.jt_account.getText());
                            }    //传学号
                            this.tableText.setVisible(true);
                            this.setVisible(false);
                            System.out.println("ok is login ");
                        } else {
                            JOptionPane.showMessageDialog(this, "密码或者用户名不正确或者账号不存在");
                        }
                    }
                    else {
                        JOptionPane.showMessageDialog(this, "account 格式错误!!");
                    }
                    this.jt_password.setText("");
                    this.jt_account.setText("");
                }
            if(actionEvent.getSource().equals(this.jb_register)){
            // 如果是登录的话 ,先看验证是否正确
      if(this.register==null){
          this.register= new Register(this,this.test);
      }
     this.setVisible(false); this.register.setVisible(true);
            }
        }
    }
    

    (3) 页面展示
    在这里插入图片描述

    3、注册页面
    (1) 这个页面虽然小但是含有的东西较多,首先要检查注册的账号在Studen表中有没有出现,没有的话不允许注册。存在的话,检查是否重复,不重复的话允许注册。为了增强安全性,加入了导入图片以及验证码的内容。
    (2)具体代码:

    
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    import static javax.swing.JOptionPane.WARNING_MESSAGE;
    public class Register extends JFrame implements ActionListener {
       //属性
        private JLabel jl_account,jl_password,jl_img,jl_img_put,jl_code;//放置图片的组件
        private  JButton jb_submit,jb_return; //传递按钮 ,返回按钮
        private  ImageIcon img; //图片
         private  JTextField jt_account,jt_img,jt_code;//输入框,输入验证码
         private  Test test;
         public Login_in login_in;
         private JPasswordField jt_password;
         private  Md5 md5;//MD5算法
        //构造方法
      private  validCode validcode;
        public Register( Login_in login_in2 ,Test test){
            super("账户注册");
            //数据流
            this.test= test;
            this.login_in=login_in2;
            // 登录页面
          this.md5= new Md5();
            //组件定义
            //图片
            this.img= new ImageIcon(getClass().getResource("/photo/7.PNG"));//使用的是getResource
            this.img.setImage(this.img.getImage().getScaledInstance(80,100, Image.SCALE_DEFAULT));
            this.jb_submit= new JButton("注册"); this.jb_submit.addActionListener(this);
            this.jt_account=new JTextField(10);
            this.jt_password= new JPasswordField(10);
            this.jt_img= new JTextField(10);
            this.jl_account= new JLabel("输入账号");
            this.jl_password= new JLabel("输入密码"); this.jt_code= new JTextField(10);
            this.jl_code= new JLabel("输入验证码");  this.jb_return= new JButton("返回");
            this.jl_img= new JLabel("输入图片路径"); this.jl_img_put= new JLabel("上传的图片");
            this.validcode= new validCode();
            this.setSize(500,650);
            //添加组件
            this.getContentPane().setLayout(null);
            //验证码
            this.getContentPane().add(this.validcode);
            this.getContentPane().add(this.jb_submit); this.getContentPane().add(this.jt_account);
         this.getContentPane().add(this.jt_password);this.getContentPane().add(this.jt_img);        this.getContentPane().add(this.jl_account);this.getContentPane().add(this.jl_img);
             this.getContentPane().add(this.jl_password); this.getContentPane().add(this.jl_img_put); this.getContentPane().add(this.jl_code);
             this.getContentPane().add(this.jt_code); this.getContentPane().add(this.jb_return); this.jb_return.addActionListener(this);
            //设置组件位置
            this.jl_account.setBounds(80,100,100,30);
            this.jt_account.setBounds(200,100,150,30);
            this.jl_password.setBounds(80,150,100,30);
            this.jt_password.setBounds(200,150,150,30);
            this.jl_img.setBounds(80,200,100,30);
            this.jt_img.setBounds(200,200,150,30);
            this.jb_submit.setBounds(120,280,80,30);this.jb_submit.setContentAreaFilled(false);
            this.jb_return.setBounds(240,280,80,30); this.jb_return.setContentAreaFilled(false);
            this.jl_code.setBounds(80,240,80,30);
            this.jt_code.setBounds(200,240,150,30);
            this.validcode.setBounds(370,230,80,30);
            this.jl_img_put.setBounds(100,380,100,30);
            //设置页面的布局
            this.setSize(500,600);
            this.setDefaultCloseOperation(Windows.EXIT_ON_CLOSE);
            this.setLocationRelativeTo(null);
            this.setVisible(true);
        }
        //画图
        public void paint(Graphics g){
        super.paint(g);//如果没有的话将会出错
          g.drawImage(this.img.getImage(),200,400,100,100,null);
        }
    //验证码是不是正确
        public boolean is_right(){
            if(this.jt_code.getText().equals(this.validcode.getCode())){
                return true;
            }
            else
                return  false;
        }
        //检查账户是否相同
        public boolean is_same(String a){
            boolean flag=true;
            String sql="select password  from account_password  where account=?";
            this.test.get_sql_connection();
            try{
             this.test.ps= this.test.ct.prepareStatement(sql);
             this.test.ps.setString(1,a);
                this.test.rs=this.test.ps.executeQuery();
                flag=this.test.rs.next();
            }
            catch (Exception e){
                e.printStackTrace();
            }
            finally{
                this.test.close();
                //记得关闭
            }
            return flag;
        }
         //学号是不是存在
        public boolean is_zai(String a){
          boolean flag=false;
           
           this.test.get_sql_connection();
           try{
               String sql="select * from Student where Sno=?";
               this.test.ps=this.test.ct.prepareStatement(sql);
               this.test.ps.setString(1,a);
               this.test.rs = this.test.ps.executeQuery();
               flag = this.test.rs.next();
           }
           catch (Exception e){
               e.printStackTrace();
           }
           finally {
               this.test.close();
           }
            return flag;
        }
        //向account_password 中插入信息
        public void  is_register(String a, String b) throws IOException {
            FileInputStream fileInputStream = null;
            File f=null;
            this.test.get_sql_connection();
            System.out.println(this.jt_img.getText());
            String sql ="insert into account_password values(?,?,?)";
            try{
                 f= new File(this.jt_img.getText());
                this.test.ps=this.test.ct.prepareStatement(sql);
                this.test.ps.setString(1,a);
                this.test.ps.setString(2,this.md5.getMd5_String(b));
                fileInputStream= new FileInputStream(f);
                this.test.ps.setBinaryStream(3,fileInputStream,(int)f.length());
                this.test.ps.executeUpdate();
                this.img = new ImageIcon(this.jt_img.getText());
                repaint();
                JOptionPane.showMessageDialog(this, "注册欧克!!!");
            }catch (Exception e){
                e.printStackTrace();
                JOptionPane.showMessageDialog(this,"图片路径有误");
            }
            finally {
                this.test.close();
            }
            fileInputStream.close();
        }
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
         if(actionEvent.getSource().equals(this.jb_submit)){
             //首先判断验证码
             if(this.jt_code.getText().isEmpty()) JOptionPane.showMessageDialog(this,"验证码不能为空");
         //验证码不正确
         else  if(is_right()==false){
              JOptionPane.showMessageDialog(this,"输入正确的验证码!");
             }
         else if(jt_img.getText().isEmpty()){
             JOptionPane.showMessageDialog(this,"需要上传图片!");
             }
         //都正确的话  进行用户,密码的检验 要求密码只能是由[A-Za-z0-9]组成
         else {
             String exr=new String(this.jt_password.getPassword());
                 Pattern p_password = Pattern.compile("^[A-Za-z0-9]{3,6}$");
                 Matcher m_password;
                 m_password = p_password.matcher(exr);
                 //检查密码组合是不是有问题
                 if(!m_password.find()){
                     JOptionPane.showMessageDialog(this,"密码是由大小写字母数字组成的3,6位组合的!");
                 }
                 //检查账户是否合理,需要访问student表判断是否存在如果没有不能创建,访问account_password表账户是否存在,存在的话,用户重复!!
                 else {
                     if (this.is_zai(this.jt_account.getText()) == false) {
                         JOptionPane.showMessageDialog(this, "学号不存在");
                     }
                     //学号存在的话:
                     else {
                         String ex2= new String(this.jt_password.getPassword());
                         if (this.is_same(this.jt_account.getText()) == true) {
                             JOptionPane.showMessageDialog(this, "账号已经存在!!");
                         } else {
                             try {
                                 this.is_register(this.jt_account.getText(),ex2);
                             } catch (IOException e) {
                                 e.printStackTrace();
                             }
                             System.out.println(this.jt_img.getText());
                         }
                         //账户存在
                     }
                     //学号存在
                 }
                 //密码符合规范
           }
         //验证码正确,图片路径不为空
            // this.jt_account.setText("");this.jt_password.setText("");this.jt_img.setText(""); this.jt_code.setText("");
         }
         //如果是注册的话
         if(actionEvent.getSource().equals(this.jb_return )){
             //返回按钮 返回到login in页面
             this.jt_code.setText("");
             this.jt_password.setText("");
             this.jt_account.setText("");
             this.jt_img.setText("");
             //重新绘制图片
             this.img= new ImageIcon(getClass().getResource("/photo/7.PNG"));//使用的是getResource
             this.img.setImage(this.img.getImage().getScaledInstance(80,100, Image.SCALE_DEFAULT));
             repaint();
             
             this.login_in.setVisible(true);
             this.setVisible(false);
         }
        }
    }
    

    (3)页面展示:
    在这里插入图片描述
    3 学生模块
    (1) 制作的系统是学生选课管理系统,因此对于学生用户而言SC是能够查询修改的,对于Student以及Course的内容是没有权限的。学生模块分为两个 页面,含有表格,按钮,JtestField等组件。因为Student具有查询的权限,因此分为两个页面。
    (2) TableTest 页面:

    public class TableText extends JFrame implements ActionListener {
         private MyDefaultTable table;
         protected  Login_in login_in; 
         // Login_in类用于返回登陆页面
         private ImageIcon img;
         protected  select_table se;
         private  JTable jTable;
         private  JScrollPane jScrollPane;
         //该学生的学号 ,由登录页面传递
         private String Sno;
         
         //按钮
         private JButton jb1_insert;
         private JButton jb3_delete;
         private  JButton jb4_select;
          private  JButton jb5_return ;
        // 输入框
        private  JLabel jl_select;
         private  JTextField insert1,delete1,select1;
         private JPanel jPanel_all;
         private JPanel jPanel;  public JPanel jPanel1,jPanel2,jPanel3;
         private  JLabel jLabel1,jl;//提示信息
        //连接数据的 类
        public Test test;
        //提示输入信息
        public JLabel jl1,jl3,jl5;
         public TableText(Login_in login_in,String s){
             this.login_in= login_in;
             this.img= new ImageIcon(getClass().getResource("/photo/10.jpg"));//导入图片
             this.jl= new JLabel(this.img);
             this.jl.setBounds(0,0,800,550);
             this.test= new Test();
             this.Sno=s;
             this.jPanel3= new JPanel();
             this.test.select("Course");
            String [] str1={ "Cno","Cname","grade"};
            this.table= new MyDefaultTable(str1,22);
            //表格中添加信息
            for(int i=1;i<=this.test.con.size();i++){
                this.table.setValueAt(this.test.con.get(i-1),i-1,0);
                this.table.setValueAt(this.test.sno.get(i-1),i-1,1);
                this.table.setValueAt(this.test.Cname.get(i-1),i-1,2);
            }
            //这个就是在Test 类中提到的vector容器
            this.test.vector_free();
            this.jTable= new JTable(this.table);this.jScrollPane= new JScrollPane(this.jTable);
            //输入框
            this.insert1=new JTextField(20);this.delete1= new JTextField(20);
           this.select1=new JTextField(20);
            //提示输入信息
            this.jl1= new JLabel("选择的课程");
            this.jl3= new JLabel("选择的课程");
            this.jl5= new JLabel("选择的课程");
            this.jl_select= new JLabel("查看你所选的课程");
            //按钮
            this.jb1_insert= new JButton("插入");  this.jb3_delete= new JButton("删除");
            this.jb4_select= new JButton("查看"); this.jb5_return= new JButton("返回");
            this.jb1_insert.addActionListener(this);
            //注册监听器
              this.jb3_delete.addActionListener(this);
            this.jb4_select.addActionListener(this);      
            this.jb5_return.addActionListener(this);
            this.jPanel= new JPanel(); this.jPanel1= new JPanel();this.jPanel2=new JPanel();//四个不同的
            this.jLabel1= new JLabel("以上是可以选择的选课信息,你可以进行查询,修改,添加,删除操作,要选择的课程!!");
            this.jPanel_all= new JPanel();
            this.jPanel_all.setLayout(new GridLayout(5,1));
             this.jb5_return.setContentAreaFilled(false);
            this.jb4_select.setContentAreaFilled(false);
            this.jb3_delete.setContentAreaFilled(false);
             this.jb1_insert.setContentAreaFilled(false);
            //分为5行1列添加组件
           this.jPanel.add(this.jb1_insert);this.jPanel.add(this.jl1);this.jPanel.add(this.insert1);        this.jPanel1.add(this.jb3_delete);this.jPanel1.add(this.jl3);this.jPanel1.add(this.delete1);
            this.jPanel2.add(this.jl_select);
           this.jPanel2.add(this.jb4_select);//this.jPanel2.add(this.jl5);this.jPanel2.add(this.select1);
            this.jPanel3.add(this.jb5_return);
            this.setLayout(new GridLayout(2,1));
            this.setSize(800,550);
            this.setLocationRelativeTo(null);
            this.setResizable(false);
            this.getContentPane().add(this.jScrollPane);        this.jPanel_all.add(this.jLabel1);this.jPanel_all.add(this.jPanel); this.jPanel_all.add(this.jPanel1);this.jPanel_all.add(this.jPanel2);
            this.jPanel_all.add(this.jPanel3);
            //设置背景图片
             this.getLayeredPane().add(this.jl, new Integer(Integer.MIN_VALUE));
             ((JPanel)this.getContentPane()).setOpaque(false);
             this.jPanel1.setOpaque(false);
             this.jPanel_all.setOpaque(false); this.jPanel.setOpaque(false); this.jPanel2.setOpaque(false); this.jPanel3.setOpaque(false);
             this.jScrollPane.setOpaque(false); this.insert1.setOpaque(false); this.delete1.setOpaque(false); this.select1.setOpaque(false);
             this.jTable.setOpaque(false);
             this.jl_select.setOpaque(false);
             this.getContentPane().add(this.jPanel_all);
            this.setVisible(true);
            this.setDefaultCloseOperation(Windows.EXIT_ON_CLOSE);
        }
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
             // insert按钮
             
            if(actionEvent.getSource().equals(this.jb1_insert)) {
                String b = this.insert1.getText();
                    try {
                        this.test.insert_SC_by_Stu(this.Sno, b);
                        JOptionPane.showMessageDialog(this, "insert 成功!!");
                    } catch (Exception e) {
                       JOptionPane.showMessageDialog(this,"输入信息错误或者不能为空!!");
                    }
            }
            //select 按钮
           if(actionEvent.getSource().equals(this.jb4_select)){
             if(this.se==null){
                 this.se= new select_table(this);
             }
             this.se.into(this.Sno);
             this.setVisible(false);
            this.se.setVisible(true);
           }
            //delete 按钮
          if(actionEvent.getSource().equals(this.jb3_delete)) {
              int i;
              String b = this.delete1.getText();
                  try {
                     i= this.test.delete_SC(this.Sno, b);
                     if(i==1) {
                         JOptionPane.showMessageDialog(this, "delete 成功!!!");
                     }
                     else {
               //因为空或者是不存在的元组直接在数据库中执行删除动作是没有问题的
                         JOptionPane.showMessageDialog(this,"输入不存在或者不能为空!");
                     }
                     } catch (Exception e) {
                      JOptionPane.showMessageDialog(this, "输入信息错误");
                  }
              }
            //return 按钮
           if(actionEvent.getSource().equals(this.jb5_return)){
                 this.setVisible(false);
                 this.login_in.setVisible(true);
           }
        }
    }
    
    

    (3)select_table页面:

    import javax.swing.table.DefaultTableCellRenderer;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    public class select_table extends JFrame implements ActionListener {
       protected  MyDefaultTable table; protected  TableText tableText;
        private  JTable jTable;
        public Test test;
        // TEST类也可以叫做数据库类
        private JTextField jTextField;
        private DefaultTableCellRenderer render;
        private  JScrollPane jScrollPane;
        public ImageIcon img;
        private int count;
        public JLabel jl; public JButton jb;
    
       public select_table(TableText tableText){
           this.tableText=tableText;
    
           this.render= new DefaultTableCellRenderer();
           this.render.setOpaque(false);
           this.img= new ImageIcon(getClass().getResource("/photo/9.png"));//导入图片
           this.jTextField = new JTextField();
           this.jl= new JLabel(this.img);
           this.jl.setBounds(0,0,this.img.getIconWidth(),this.img.getIconHeight());
           this.test= new Test();
           this.jb= new JButton("return ");
        //   this.jPanel= new JPanel();
         // this.jPanel2= new JPanel();
           String []sc={"Sno","Cno","Cname"};
           this.table= new MyDefaultTable(sc,22);
           this.jTable= new JTable(this.table);this.jScrollPane= new JScrollPane(this.jTable);
           this.setSize(this.img.getIconWidth(),this.img.getIconHeight());
           //流布局
           this.setLayout(null);
           this.jb.addActionListener(this);
           this.jScrollPane.setBounds(100,this.img.getIconHeight()/2-40,350,260);
           this.jb.setBounds(450,this.img.getIconHeight()/2+190,80,30);
           this.jTextField.setBounds(225,this.img.getIconHeight()/2+230,80,30);
           //this.jPanel.setLayout(new GridLayout(2,1));
           //this.jPanel2.add(this.jb);
          //this.jPanel.add(this.jScrollPane);this.jPanel.add(this.jPanel2);
           this.getLayeredPane().add(this.jl, new Integer(Integer.MIN_VALUE));
           ((JPanel)this.getContentPane()).setOpaque(false);
           for(int i=0;i<=2;i++){
               this.jTable.getColumn(sc[i]).setCellRenderer(this.render);
           }//需要渲染
           this.jScrollPane.setOpaque(false);
           this.jTable.setOpaque(false);
           this.jScrollPane.getViewport().setOpaque(false);
           this.jTextField.setOpaque(false);
          // this.getContentPane().add(this.jPanel);
           this.jb.setContentAreaFilled(false);
           //this.jPanel.setOpaque(false); this.jPanel2.setOpaque(false);
           this.getContentPane().add(this.jTextField);
           this.getContentPane().add(this.jScrollPane);this.getContentPane().add(this.jb);
           this.setDefaultCloseOperation(Windows.EXIT_ON_CLOSE);
           this.setLocationRelativeTo(null);
           this.setVisible(true);
       }
    public void into(String s){
    // 需要将页面清空一下
           try{
               for( int i=0;i<22;i++){
                   this.table.setValueAt("",i,0);
                   this.table.setValueAt("",i,1);
                   this.table.setValueAt("",i,2);
               }
              int i=0;
               this.test.get_sql_connection();
               this.test.ps=this.test.ct.prepareStatement("{call pro_tran(?)}");
               //这个是调用
               this.test.ps.setString(1,s);
               this.test.rs= this.test.ps.executeQuery();
               while (this.test.rs.next()){
                   this.table.setValueAt(this.test.rs.getString(1),i,0);
                   this.table.setValueAt(this.test.rs.getString(2),i,1);
                   this.table.setValueAt(this.test.rs.getString(3),i,2);
               i++;
               this.count=i;
               }
           }catch (Exception e){
               e.printStackTrace();
           }
           finally {
               this.test.close();
           }
           this.jTextField.setText("共有"+this.count+"记录");
           //统计功能
    }
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
           if(actionEvent.getSource().equals(this.jb)){
               //返回的按钮
            this.tableText.setVisible(true);
             this.setVisible(false);
           }
        }
    }
    
    

    (3)页面展示:
    在这里插入图片描述
    (这个是有背景图片的)
    在这里插入图片描述(致敬一下欧拉)
    四、教师模块
    (1)自定义 Windows 页面 :这个类可以比作为中转站

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.Base64;
    import javax.swing.event.*;
    public class Windows  extends JFrame implements ActionListener {
    public Test test;
        public Login_in login_in =null;
        protected Cour_tea cour_tea;
       private  Stu_tea stu_tea;
       private  SC_tea sc_tea;
       private ImageIcon img;
    
        public JButton jb_back;
        public JButton jb_Student,jb_SC,jb_Course;
        // 容器
        //图片
        public ImageIcon Icon ; public JLabel jl1;
        // 提示信息
        private JLabel jl_Student,jl_SC,jl_Course,jl;
        public Windows(Login_in login_in ,Test test){
            super("ADMIN");
            this.login_in=login_in;
           this.test= test;
            this.img= new ImageIcon(getClass().getResource("/photo/14.jpg"));//导入图片
            this.jl= new JLabel(this.img);
            this.jl.setBounds(0,0,800,600);
            //定义图片
            //this.Icon= new ImageIcon(getClass().getResource("/photo/5.jpg"));//使用的是getResource
           // this.Icon.setImage(this.Icon.getImage().getScaledInstance(500,300,Image.SCALE_DEFAULT));
            this.jl1= new JLabel();
           // this.jl1.setIcon(this.Icon);//设置图片位置
            //按钮
            this.jb_back= new JButton("return");
            this.jb_back.addActionListener(this);
    
            this.jb_SC= new JButton("SC "); this.jb_Student= new JButton("Student");this.jb_Course= new JButton("Course");
            this.jb_SC.addActionListener(this); this.jb_Course.addActionListener(this); this.jb_Student.addActionListener(this);
            this.jb_back.addActionListener(this);
    
             //提示信息
            this.jl_Course= new JLabel("Course 表"); this.jl_SC= new JLabel("SC 表");this.jl_Student= new JLabel("Student 表");
           //设置尺寸大小 布局方式
    
            this.setSize(800,600);
            this.getLayeredPane().add(this.jl, new Integer(Integer.MIN_VALUE));
            ((JPanel)this.getContentPane()).setOpaque(false);
            this.setLayout(null);
            this.jl_SC.setBounds(480,150,80,30); this.jl_SC.setOpaque(false);
            this.jb_SC.setBounds(600,150,80,30);
            this.jl_Student.setBounds(480,200,80,30);this.jl_Student.setOpaque(false);
            this.jb_Student.setBounds(600,200,80,30);
            this.jl_Course.setBounds(480,250,80,30); this.jl_Course.setOpaque(false);
            this.jb_Course.setBounds(600,250,80,30);
            this.jb_back.setBounds(550,300,80,30);
    
            // 容器添加组件
            this.jb_back.setContentAreaFilled(false); this.jb_Student.setContentAreaFilled(false);
            this.jb_Course.setContentAreaFilled(false); this.jb_SC.setContentAreaFilled(false);
             //this.getContentPane().add(this.jl1);
            this.getContentPane().add(this.jb_SC);this.getContentPane().add(this.jb_Student);this.getContentPane().add(this.jb_Course);this.getContentPane().add(this.jb_back);
             this.getContentPane().add(this.jl_Course);this.getContentPane().add(this.jl_Student);
             this.getContentPane().add(this.jl_SC);
            this.setLocationRelativeTo(null);
             this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            this.setVisible(true);
        }
    
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
     if(actionEvent.getSource().equals(this.jb_back)){
      // 返回主页面
         this.setVisible(false);
         this.login_in.setVisible(true);
     }
     // SC页面
     if(actionEvent.getSource().equals(this.jb_SC)){
         if(this.sc_tea==null){
             this.sc_tea=new SC_tea(this,this.test);
         }
         else
             this.sc_tea.setVisible(true);
         this.setVisible(false);
     }
     //Student 页面
    if(actionEvent.getSource().equals(this.jb_Student)){
        if(this.stu_tea==null){
          this.stu_tea=new Stu_tea(this,this.test);
        }
        else this.stu_tea.setVisible(true);
        this.setVisible(false);
    }
    //Course 页面
    if(actionEvent.getSource().equals(this.jb_Course)){
        if(this.cour_tea==null){
            this.cour_tea= new Cour_tea(this,this.test);
        }
        else this.cour_tea.setVisible(true);
        this.setVisible(false);
    }
        }
    }
    

    在这里插入图片描述

    (2)SC页面 教师对学生的选课进行管理:除了基本的功能还具有统计排序功能

    import javax.swing.*;
    import javax.swing.table.DefaultTableCellRenderer;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.sql.SQLException;
    public class SC_tea extends JFrame implements ActionListener {
        //表格信息
        public Windows windows;
        private MyDefaultTable table;
        private  JTable jTable;
        private  JScrollPane jScrollPane;
        private DefaultTableCellRenderer render;
        private Test test;
        private JTextField jTextField;
        private ImageIcon img;
        private int count;
        //按钮
        protected JButton jb_insert ,jb_select ,jb_update,jb_delete,jb_back,jb_order,jb_select2,jb_select_sc;
        //布局容器
        protected  JPanel jp_all,jp_insert ,jp_update,jp_delete,jp_select,jp_back,jp_1;
        //输入信息
        protected  JTextField jt_insert,jt_insert2,jt_insert3;
        protected  JTextField jt_update,jt_update2,jt_update3;
        protected  JTextField jt_delete,jt_delete2,jt_delete3;
        protected  JTextField jt_select,jt_order,jt_select2;
        //提示信息
        protected  JLabel jl_insert,jl_insert2,jl_insert3,jl;
        protected  JLabel jl_update,jl_update2,jl_update3;
        protected  JLabel jl_select,jl_order,jl_select2;
        protected  JLabel jl_delete,jl_delete2,jl_delete3;
        //构造
        public SC_tea(Windows windows, Test test){
           //表格
            super("SC");
    
            this.windows=windows;
            this.test=test;
            this.render= new DefaultTableCellRenderer();
            this.render.setOpaque(false);
            this.img= new ImageIcon(getClass().getResource("/photo/12.jpg"));//导入图片
            this.jl= new JLabel(this.img);
            this.jl.setBounds(0,0,1000,700);
            String []str={"Sno","Cno","Grade"};
            this.table=new MyDefaultTable(str,22);
            this.jb_select2= new JButton("查询课程");
            this.jb_select_sc=new JButton("查看所有");
            this.jTable= new JTable(this.table);
            this.jScrollPane= new JScrollPane(this.jTable);
            //按钮
            this.jb_delete= new JButton("删除");this.jb_insert= new JButton("插入");
            this.jb_select= new JButton("查看学生");this.jb_update= new JButton("更新");
            this.jb_update.addActionListener(this); this.jb_select.addActionListener(this);
            this.jb_insert.addActionListener(this);this.jb_delete.addActionListener(this);
            this.jb_back= new JButton("return"); this.jb_back.addActionListener(this);
            this.jb_order= new JButton("排序");this.jb_order.addActionListener(this);
            this.jb_select_sc.addActionListener(this);
            this.jb_select2.addActionListener(this);
            //输入信息 提示信息
             // insert
             this.jt_insert= new JTextField(10);this.jt_insert2= new JTextField(10);this.jt_insert3= new JTextField(10);
             this.jl_insert = new JLabel("学号"); this.jl_insert2= new JLabel("选课编号"); this.jl_insert3= new JLabel("成绩");
              this.jt_insert.setOpaque(false); this.jt_insert2.setOpaque(false); this.jt_insert3.setOpaque(false);
              this.jl_insert.setOpaque(false); this.jl_insert2.setOpaque(false); this.jl_insert3.setOpaque(false);
                this.jTextField= new JTextField(10);
             // update
              this.jt_update= new JTextField(10);this.jt_update2= new JTextField(10);this.jt_update3= new JTextField(10);
              this.jl_update = new JLabel("学号"); this.jl_update2= new JLabel("选课编号");this.jl_update3= new JLabel("成绩");
              this.jt_update.setOpaque(false); this.jt_update2.setOpaque(false); this.jt_update3.setOpaque(false);
              this.jl_update.setOpaque(false); this.jl_update2.setOpaque(false); this.jl_update3.setOpaque(false);
              // select
             this.jt_select = new JTextField(10); this.jl_select2= new JLabel("输入课程编号"); this.jt_select2= new JTextField(10);
             this.jl_select= new JLabel("学号"); this.jt_order= new JTextField(10); this.jl_order=new JLabel("输入课程编号");
             this.jt_select.setOpaque(false); this.jl_select2.setOpaque(false); this.jt_select2.setOpaque(false);
             this.jl_select.setOpaque(false); this.jt_order.setOpaque(false); this.jl_order.setOpaque(false);
             // delete
             this.jt_delete= new JTextField(10);this.jt_delete2= new JTextField(10);this.jt_delete3= new JTextField(10);
             this.jl_delete= new JLabel("学号");this.jl_delete2= new JLabel("选课编号");this.jl_delete3= new JLabel("成绩");
             this.jt_delete.setOpaque(false); this.jt_delete2.setOpaque(false); this.jt_delete3.setOpaque(false);
             this.jl_delete.setOpaque(false); this.jl_delete2.setOpaque(false); this.jl_delete3.setOpaque(false);
            //容器
            this.jp_all= new JPanel();this.jp_insert= new JPanel();this.jp_select= new JPanel();this.jp_update= new JPanel();
            this.jp_delete= new JPanel(); this.jp_back=new JPanel(); this.jp_1= new JPanel();
            //布局
            this.setSize(1000,700);
            this.setLayout(new GridLayout(2,1));
             this.getContentPane().add(this.jScrollPane);
            this.getLayeredPane().add(this.jl, new Integer(Integer.MIN_VALUE));
            ((JPanel)this.getContentPane()).setOpaque(false);
            for(int i=0;i<=2;i++){
                this.jTable.getColumn(str[i]).setCellRenderer(this.render);
            }
            this.jScrollPane.setOpaque(false);
            this.jTable.setOpaque(false);
            this.jScrollPane.getViewport().setOpaque(false);
             this.jp_all.setLayout(new GridLayout(6,1));
             // jp_insert
            this.jp_insert.setOpaque(false); this.jTextField.setOpaque(false);
            this.jp_insert.add(this.jTextField);        this.jp_insert.add(this.jb_insert);this.jp_insert.add(this.jl_insert);this.jp_insert.add(this.jt_insert);        this.jp_insert.add(this.jl_insert2);this.jp_insert.add(this.jt_insert2);this.jp_insert.add(this.jl_insert3);this.jp_insert.add(this.jt_insert3);
            // jp_update
            this.jp_update.setOpaque(false);       this.jp_update.add(this.jb_update);this.jp_update.add(this.jl_update);this.jp_update.add(this.jt_update);this.jp_update.add(this.jl_update2);
            this.jp_update.add(this.jt_update2);this.jp_update.add(this.jl_update3);this.jp_update.add(this.jt_update3);
            // jp_delete
            this.jp_delete.setOpaque(false);       this.jp_delete.add(this.jb_delete);this.jp_delete.add(this.jl_delete);this.jp_delete.add(this.jt_delete);       this.jp_delete.add(this.jl_delete2);this.jp_delete.add(this.jt_delete2);
            this.jp_delete.add(this.jl_delete3);this.jp_delete.add(this.jt_delete3);
            //jp_select
            this.jp_select.setOpaque(false);
            this.jp_select.add(this.jb_select);this.jp_select.add(this.jl_select);this.jp_select.add(this.jt_select);
             this.jp_select.add(this.jb_select2);this.jp_select.add(this.jl_select2);this.jp_select.add(this.jt_select2);
           //
            this.jp_back.setOpaque(false);
           this.jp_back.add(this.jb_order); this.jp_back.add(this.jl_order);this.jp_back.add(this.jt_order);
           //
            this.jp_1.setOpaque(false);
            this.jp_1.add(this.jb_select_sc); this.jp_1.add(this.jb_back);
           //布局
            this.jp_all.setOpaque(false);
             this.jp_all.add(this.jp_insert);this.jp_all.add(this.jp_update);this.jp_all.add(this.jp_delete);this.jp_all.add(this.jp_select);this.jp_all.add(this.jp_back);
            this.jp_all.add(this.jp_1);
            //jb_insert ,jb_select ,jb_update,jb_delete,jb_back,jb_order,jb_select2,jb_select_sc;
            this.jb_insert.setContentAreaFilled(false); this.jb_select.setContentAreaFilled(false);
            this.jb_update.setContentAreaFilled(false); this.jb_delete.setContentAreaFilled(false);
            this.jb_back.setContentAreaFilled(false); this.jb_order.setContentAreaFilled(false);
            this.jb_select2.setContentAreaFilled(false); this.jb_select_sc.setContentAreaFilled(false);
              //设置
             this.getContentPane().add(this.jp_all);
            this.setLocationRelativeTo(null);
            this.setDefaultCloseOperation(Windows.EXIT_ON_CLOSE);
            this.setVisible(true);
        }
        //在table添加数据
        public void into (){
            try{
                int i=0;
                this.test.get_sql_connection();
                this.test.ps=this.test.ct.prepareStatement("select * from SC ");
                this.test.rs= this.test.ps.executeQuery();
                for (int j=i;j<22;j++){
                    this.table.setValueAt(null,i,0);
                    this.table.setValueAt(null,i,1);
                    this.table.setValueAt(null,i,2);
                }
                while (this.test.rs.next()){
                    this.table.setValueAt(this.test.rs.getString(1),i,0);
                    this.table.setValueAt(this.test.rs.getString(2),i,1);
                    this.table.setValueAt(this.test.rs.getString(3),i,2);
                    i++;
                    this.count=i;
                }
    
            }catch (Exception e){
                e.printStackTrace();
            }
            finally {
                this.test.close();
            }
            this.jTextField.setText("");
            this.jTextField.setText("共有"+this.count+"记录");
        }
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
      // insert
            if(actionEvent.getSource().equals(this.jb_insert)){
            String a=this.jt_insert.getText();
            String b= this.jt_insert2.getText();
            String c= this.jt_insert3.getText();
                try {
                    this.test.insert_SC_by_tea(a,b,c);
                    JOptionPane.showMessageDialog(this,"加入成功");
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(this,"检查输入!!");
                }
      }
            //delete
            if(actionEvent.getSource().equals(this.jb_delete)){
               int i;
                String a=this.jt_delete.getText();
               String b=this.jt_delete2.getText();
                try {
                    i=this.test.delete_SC(a,b);
                   if(i==1){
                       JOptionPane.showMessageDialog(this,"删除成功!!");
                   }
                    else {
                        JOptionPane.showMessageDialog(this,"信息错误!!");
                   }
                } catch (SQLException e) {
                  JOptionPane.showMessageDialog(this,"检查输入!!");
                }
            }
            // update
            if(actionEvent.getSource().equals(this.jb_update)){
                String a=this.jt_update.getText();
                String b=this.jt_update2.getText();
                String c=this.jt_update3.getText();
                System.out.println(c);
                try {
                    if(this.test.update_sc_by_tea(a,b,c)==1){
                        JOptionPane.showMessageDialog(this,"更新成功!");
                    }
                    else{
                        JOptionPane.showMessageDialog(this,"检查输入!");
                    }
                } catch (Exception e) {
                 JOptionPane.showMessageDialog(this,"ERROR 检查输入!!");
                }
            }
            //学号查询
            if(actionEvent.getSource().equals(this.jb_select)){
                String a=this.jt_select.getText();
                try{
                    for(int j=0;j<22;j++){
                        this.table.setValueAt(null,j,0);
                        this.table.setValueAt(null,j,1);
                        this.table.setValueAt(null,j,2);
                    }
                    int i=0;
                    this.test.get_sql_connection();
                    this.test.ps=this.test.ct.prepareStatement("select * from SC where Sno ="+a);
                    this.test.rs= this.test.ps.executeQuery();
                    while (this.test.rs.next()){
                        this.table.setValueAt(this.test.rs.getString(1),i,0);
                        this.table.setValueAt(this.test.rs.getString(2),i,1);
                        this.table.setValueAt(this.test.rs.getString(3),i,2);
                        i++;
                     this.count=i;
                    }
                }catch (Exception e){
                  JOptionPane.showMessageDialog(this,"检查输入!!");
                }
                finally {
                    this.test.close();
                }
                this.jTextField.setText("");
                //统计功能
                this.jTextField.setText("共有"+this.count+"记录");
            }
            //课程查询
            if(actionEvent.getSource().equals(this.jb_select2)){
                String a=this.jt_select2.getText();
                try{
                    int i=0;
                    this.test.get_sql_connection();
                    this.test.ps=this.test.ct.prepareStatement("select * from SC where Cno ="+a);
                    this.test.rs= this.test.ps.executeQuery();
                    for(int j=i;j<22;j++){
                        this.table.setValueAt(null,j,0);
                        this.table.setValueAt(null,j,1);
                        this.table.setValueAt(null,j,2);
                    }
                    while (this.test.rs.next()){
                       this.table.setValueAt(this.test.rs.getString(1),i,0);
                        this.table.setValueAt(this.test.rs.getString(2),i,1);
                        this.table.setValueAt(this.test.rs.getString(3),i,2);
                        i++;
                    }
                  this.count=i;
                }catch (Exception e){
                   JOptionPane.showMessageDialog(this,"检查输入!!!!");
                }
                finally {
                    this.test.close();
                }
                this.jTextField.setText("共有"+this.count+"记录");
            }
            //排序
            if(actionEvent.getSource().equals(this.jb_order)){
                String a=this.jt_order.getText();
                try{
                    int i=0;
                    this.test.get_sql_connection();
                    this.test.ps=this.test.ct.prepareStatement("select * from SC where Cno ="+a+" order by Grade");
                    this.test.rs= this.test.ps.executeQuery();
                    while (this.test.rs.next()){
                        this.table.setValueAt(this.test.rs.getString(1),i,0);
                        this.table.setValueAt(this.test.rs.getString(2),i,1);
                        this.table.setValueAt(this.test.rs.getString(3),i,2);
                        i++;
                    }
                    for(int j=i;j<22;j++){
                        this.table.setValueAt(null,j,0);
                        this.table.setValueAt(null,j,1);
                        this.table.setValueAt(null,j,2);
                    }
                }catch (Exception e){
                   JOptionPane.showMessageDialog(this,"检查输入!!");
                }
                finally {
                    this.test.close();
                }
                this.jTextField.setText("");
            }
            //查看所有选课记录
      if(actionEvent.getSource().equals(this.jb_select_sc)){
          this.into();
      }
      //返回
      if(actionEvent.getSource().equals(this.jb_back)){
         this.windows.setVisible(true);
          this.setVisible(false);
      }
    }
    }
    

    在这里插入图片描述
    (3)Student 表学生的属性,管理员教师可以管理 这个页面相比之较为简单。

    import javax.swing.*;
    import javax.swing.table.DefaultTableCellRenderer;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.sql.SQLException;
    public class Stu_tea extends JFrame implements ActionListener {
         public Windows windows;
        private MyDefaultTable table;
        private ImageIcon img;
        private DefaultTableCellRenderer render;
        private  JTable jTable;
        private  JScrollPane jScrollPane;
        private Test test;
        public JButton jb_delete,jb_select,jb_update,jb_insert,jb_back;
        //布局容器
        protected  JPanel jp_all,jp_insert ,jp_update,jp_delete,jp_select;
        //输入信息
        protected  JTextField jt_insert,jt_insert2,jt_insert3;
        protected  JTextField jt_update,jt_update2,jt_update3;
        protected  JTextField jt_delete,jt_delete2,jt_delete3;
    
        //提示信息
        protected  JLabel jl_insert,jl_insert2,jl_insert3,jl;
        protected  JLabel jl_update,jl_update2,jl_update3;
    
        protected  JLabel jl_delete,jl_delete2,jl_delete3;
        public Stu_tea(Windows windows,Test test){
            super("Student");
            this.render= new DefaultTableCellRenderer();
            this.render.setOpaque(false);
            this.img= new ImageIcon(getClass().getResource("/photo/13.jpg"));//导入图片
            this.jl= new JLabel(this.img);
            this.jl.setBounds(0,0,1000,700);
              this.windows=windows;
            this.test=  test;
            String []str={"学号","姓名","年龄"};
            this.table=new MyDefaultTable(str,22);
            this.jTable= new JTable(this.table);
            this.jScrollPane= new JScrollPane(this.jTable);
            //按钮
            this.jb_delete= new JButton("删除");this.jb_insert= new JButton("插入");
            this.jb_select= new JButton("查看");this.jb_update= new JButton("更新");
            this.jb_update.addActionListener(this); this.jb_select.addActionListener(this);
            this.jb_insert.addActionListener(this);this.jb_delete.addActionListener(this);
            this.jb_back= new JButton("return"); this.jb_back.addActionListener(this);
            // insert
            this.jt_insert= new JTextField(10);this.jt_insert2= new JTextField(10);this.jt_insert3= new JTextField(10);
            this.jl_insert = new JLabel("学号"); this.jl_insert2= new JLabel("姓名"); this.jl_insert3= new JLabel("年龄");
            this.jt_insert.setOpaque(false); this.jt_insert2.setOpaque(false); this.jt_insert3.setOpaque(false);
            this.jl_insert.setOpaque(false); this.jl_insert2.setOpaque(false); this.jl_insert3.setOpaque(false);
            // update
            this.jt_update= new JTextField(10);this.jt_update2= new JTextField(10);this.jt_update3= new JTextField(10);
            this.jl_update = new JLabel("学号"); this.jl_update2= new JLabel("姓名");this.jl_update3= new JLabel("年龄");
            this.jt_update.setOpaque(false); this.jt_update2.setOpaque(false); this.jt_update3.setOpaque(false);
            this.jl_update.setOpaque(false); this.jl_update2.setOpaque(false); this.jl_update3.setOpaque(false);        // select
            // delete
            this.jt_delete= new JTextField(10);this.jt_delete2= new JTextField(10);this.jt_delete3= new JTextField(10);
            this.jl_delete= new JLabel("学号");this.jl_delete2= new JLabel("姓名");this.jl_delete3= new JLabel("年龄");
            this.jt_delete.setOpaque(false); this.jt_delete2.setOpaque(false); this.jt_delete3.setOpaque(false);
            this.jl_delete.setOpaque(false); this.jl_delete2.setOpaque(false); this.jl_delete3.setOpaque(false);
            //容器
            this.jp_all= new JPanel();this.jp_insert= new JPanel();this.jp_select= new JPanel();this.jp_update= new JPanel();
            this.jp_delete= new JPanel();
            //布局
            this.setSize(1000,700);
            this.setLayout(new GridLayout(2,1));
            this.getContentPane().add(this.jScrollPane);
            this.jp_all.setLayout(new GridLayout(4,1));
            // jp_insert
            this.jp_insert.add(this.jb_insert);this.jp_insert.add(this.jl_insert);this.jp_insert.add(this.jt_insert);
            this.jp_insert.add(this.jl_insert2);this.jp_insert.add(this.jt_insert2);this.jp_insert.add(this.jl_insert3);this.jp_insert.add(this.jt_insert3);
            // jp_update
            this.jp_update.add(this.jb_update);this.jp_update.add(this.jl_update);this.jp_update.add(this.jt_update);this.jp_update.add(this.jl_update2);
            this.jp_update.add(this.jt_update2);this.jp_update.add(this.jl_update3);this.jp_update.add(this.jt_update3);
            // jp_delete
            this.jp_delete.add(this.jb_delete);this.jp_delete.add(this.jl_delete);this.jp_delete.add(this.jt_delete);
            this.jp_delete.add(this.jl_delete2);this.jp_delete.add(this.jt_delete2);
            this.jp_delete.add(this.jl_delete3);this.jp_delete.add(this.jt_delete3);
            //jp_select
            this.jp_select.add(this.jb_select);
          this.jp_select.add(this.jb_back);
            //布局
            this.jp_all.setOpaque(false);
            this.jp_insert.setOpaque(false); this.jp_update.setOpaque(false); this.jp_delete.setOpaque(false);
            this.jp_select.setOpaque(false);
            this.jp_all.add(this.jp_insert);this.jp_all.add(this.jp_update);this.jp_all.add(this.jp_delete);this.jp_all.add(this.jp_select);
            //jb_delete,jb_select,jb_update,jb_insert,jb_back; 组件为空
    
            this.jb_delete.setContentAreaFilled(false); this.jb_back.setContentAreaFilled(false); this.jb_insert.setContentAreaFilled(false);
            this.jb_select.setContentAreaFilled(false); this.jb_update.setContentAreaFilled(false);
            //设置
            this.getLayeredPane().add(this.jl, new Integer(Integer.MIN_VALUE));
            ((JPanel)this.getContentPane()).setOpaque(false);
            for(int i=0;i<=2;i++){
                this.jTable.getColumn(str[i]).setCellRenderer(this.render);
            }
            this.jScrollPane.setOpaque(false);
            this.jTable.setOpaque(false);
            this.jScrollPane.getViewport().setOpaque(false);
            this.getContentPane().add(this.jp_all);
            this.setLocationRelativeTo(null);
            this.setDefaultCloseOperation(Windows.EXIT_ON_CLOSE);
            this.setVisible(true);
        }
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
      //insert 功能
       if(actionEvent.getSource().equals(this.jb_insert)) {
           try {
               String a = this.jt_insert.getText();
               String b = this.jt_insert2.getText();
               String c = this.jt_insert3.getText();
               this.test.insert_by_tea(a, b, c, "Student");
           JOptionPane.showMessageDialog(this,"ok!");
           }
           catch (Exception e){
               e.printStackTrace();
               JOptionPane.showMessageDialog(this,"请检查输入信息!!");
           }
       }
       // delete 功能
            if(actionEvent.getSource().equals(this.jb_delete)) {
                String a = this.jt_delete.getText();
                if (a.equals("")) {
                   JOptionPane.showMessageDialog(this,"ERROR 检查输入!!");
                } else {
                    try {
                        this.test.delete(a);
                        JOptionPane.showMessageDialog(this, "delete ok!!!");
                    } catch (Exception e) {
                        JOptionPane.showMessageDialog(this, "ERROR!!!");
                    }
                }
            }
        // update
           if(actionEvent.getSource().equals(this.jb_update)){
          String a =this.jt_update.getText();
          String b=this.jt_update2.getText();
          String c=this.jt_update3.getText();
               try {
                   if(this.test.update_Student_tea(a,b,c)==1){
                       JOptionPane.showMessageDialog(this,"update ok!!");
                   }
                   else {
                       JOptionPane.showMessageDialog(this,"检查输入!");
                   }
               } catch (Exception e) {
                  JOptionPane.showMessageDialog(this,"ERROR!!! 检查输入信息");
               }
           }
           // select
           if(actionEvent.getSource().equals(this.jb_select)){
               try{
                   int i=0;
                   this.test.get_sql_connection();
                   this.test.ps=this.test.ct.prepareStatement("select * from Student");
                   this.test.rs= this.test.ps.executeQuery();
                   while (this.test.rs.next()){
                       this.table.setValueAt(this.test.rs.getString(1),i,0);
                       this.table.setValueAt(this.test.rs.getString(2),i,1);
                       this.table.setValueAt(this.test.rs.getString(3),i,2);
                       i++;
                   }
               }catch (Exception e){
                  JOptionPane.showMessageDialog(this,"检查输入信息");
               }
               finally {
                   this.test.close();
               }
           }
            if(actionEvent.getSource().equals(this.jb_back)){
                //返回
                  this.setVisible(false);
                  this.windows.setVisible(true);
            }
        }
    }
    

    在这里插入图片描述
    (4)Course页面 用于记录课程

    import javax.swing.*;
    import javax.swing.table.DefaultTableCellRenderer;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.sql.SQLException;
    public class Cour_tea extends JFrame implements ActionListener {
       public Windows windows;
        private MyDefaultTable table;
        private  JTable jTable;
        private  JScrollPane jScrollPane;
        private ImageIcon img;
        private Test test;
        private  DefaultTableCellRenderer render;
        public JButton jb_delete,jb_select,jb_update,jb_insert,jb_back;
        //布局容器
        protected  JPanel jp_all,jp_insert ,jp_update,jp_delete,jp_select;
        //输入信息
        protected  JTextField jt_insert,jt_insert2,jt_insert3;
        protected  JTextField jt_update,jt_update2,jt_update3;
        protected  JTextField jt_delete,jt_delete2,jt_delete3;
        //提示信息
        protected  JLabel jl_insert,jl_insert2,jl_insert3,jl;
        protected  JLabel jl_update,jl_update2,jl_update3;
        protected  JLabel jl_delete,jl_delete2,jl_delete3;
        public Cour_tea(Windows windows ,Test test){
            super(" Course ");
            this.windows= windows;
            this.test=  test;
            this.render= new DefaultTableCellRenderer();
            this.render.setOpaque(false);
            this.img= new ImageIcon(getClass().getResource("/photo/11.jpg"));//导入图片
            this.jl= new JLabel(this.img);
            this.jl.setBounds(0,0,1200,700);
            String []str={"课程编号","课程名","学分"};
            this.table=new MyDefaultTable(str,22);
            this.jTable= new JTable(this.table);
            this.jScrollPane= new JScrollPane(this.jTable);
            //按钮
            this.jb_delete= new JButton("删除");this.jb_insert= new JButton("插入");
            this.jb_select= new JButton("查看");this.jb_update= new JButton("更新");
            this.jb_update.addActionListener(this); this.jb_select.addActionListener(this);
            this.jb_insert.addActionListener(this);this.jb_delete.addActionListener(this);
            this.jb_back= new JButton("return"); this.jb_back.addActionListener(this);
            // insert
            this.jt_insert= new JTextField(10);this.jt_insert2= new JTextField(10);this.jt_insert3= new JTextField(10);
            this.jl_insert = new JLabel("课程编号"); this.jl_insert2= new JLabel("课程名"); this.jl_insert3= new JLabel("学分");
            this.jt_insert.setOpaque(false); this.jt_insert2.setOpaque(false); this.jt_insert3.setOpaque(false);
            this.jl_insert.setOpaque(false); this.jl_insert2.setOpaque(false); this.jl_insert3.setOpaque(false);
            // update
            this.jt_update= new JTextField(10);this.jt_update2= new JTextField(10);this.jt_update3= new JTextField(10);
            this.jl_update = new JLabel("课程编号"); this.jl_update2= new JLabel("课程名");this.jl_update3= new JLabel("学分");
            this.jt_update.setOpaque(false); this.jt_update2.setOpaque(false); this.jt_update3.setOpaque(false);
            this.jl_update.setOpaque(false); this.jl_update2.setOpaque(false); this.jl_update3.setOpaque(false);
            // select
            // delete
            this.jt_delete= new JTextField(10);this.jt_delete2= new JTextField(10);this.jt_delete3= new JTextField(10);
            this.jl_delete= new JLabel("课程编号");this.jl_delete2= new JLabel("课程名");this.jl_delete3= new JLabel("学分");
            this.jt_delete.setOpaque(false); this.jt_delete2.setOpaque(false); this.jt_delete3.setOpaque(false);
            this.jl_delete.setOpaque(false); this.jl_delete2.setOpaque(false); this.jl_delete3.setOpaque(false);
            //容器
            this.jp_all= new JPanel();this.jp_insert= new JPanel();this.jp_select= new JPanel();this.jp_update= new JPanel();
            this.jp_delete= new JPanel();
            //布局
            this.setSize(1200,700);
            this.setLayout(new GridLayout(2,1));
            this.getContentPane().add(this.jScrollPane);
            this.jp_all.setLayout(new GridLayout(4,1));
            // jp_insert
            this.jp_insert.setOpaque(false);
        this.jp_insert.add(this.jb_insert);this.jp_insert.add(this.jl_insert);this.jp_insert.add(this.jt_insert);
            this.jp_insert.add(this.jl_insert2);this.jp_insert.add(this.jt_insert2);this.jp_insert.add(this.jl_insert3);this.jp_insert.add(this.jt_insert3);
            // jp_update
            this.jp_update.setOpaque(false);
            this.jp_update.add(this.jb_update);this.jp_update.add(this.jl_update);this.jp_update.add(this.jt_update);this.jp_update.add(this.jl_update2);
            this.jp_update.add(this.jt_update2);this.jp_update.add(this.jl_update3);this.jp_update.add(this.jt_update3);
            // jp_delete
            this.jp_delete.setOpaque(false);
            this.jp_delete.add(this.jb_delete);this.jp_delete.add(this.jl_delete);this.jp_delete.add(this.jt_delete);
            this.jp_delete.add(this.jl_delete2);this.jp_delete.add(this.jt_delete2);      this.jp_delete.add(this.jl_delete3);this.jp_delete.add(this.jt_delete3);
            //jp_select
            this.jp_select.setOpaque(false);
            this.jp_select.add(this.jb_select);
            this.jp_select.add(this.jb_back);
            //布局
            this.jp_all.setOpaque(false);       this.jp_all.add(this.jp_insert);this.jp_all.add(this.jp_update);this.jp_all.add(this.jp_delete);this.jp_all.add(this.jp_select);
          //jb_delete,jb_select,jb_update,jb_insert,jb_back;
             this.jb_delete.setContentAreaFilled(false); this.jb_select.setContentAreaFilled(false);
             this.jb_update.setContentAreaFilled(false); this.jb_insert.setContentAreaFilled(false);
             this.jb_back.setContentAreaFilled(false);
            //设置
            this.getLayeredPane().add(this.jl, new Integer(Integer.MIN_VALUE));
            ((JPanel)this.getContentPane()).setOpaque(false);
            for(int i=0;i<=2;i++){
                this.jTable.getColumn(str[i]).setCellRenderer(this.render);
            }
            this.jScrollPane.setOpaque(false);
            this.jTable.setOpaque(false);
            this.jScrollPane.getViewport().setOpaque(false);
            this.getContentPane().add(this.jp_all);
            this.setLocationRelativeTo(null);
            this.setDefaultCloseOperation(Windows.EXIT_ON_CLOSE);
            this.setVisible(true);
        }
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            if(actionEvent.getSource().equals(this.jb_insert)) {
                try {
                    String a = this.jt_insert.getText();
                    String b = this.jt_insert2.getText();
                    String c = this.jt_insert3.getText();
                    this.test.insert_by_tea(a, b, c, "Course");
                   JOptionPane.showMessageDialog(this,"插入成功!");
                }
                catch (Exception e){
                    e.printStackTrace();
                    JOptionPane.showMessageDialog(this,"ERROR!!");
                }
            }
            // delete 功能
            if(actionEvent.getSource().equals(this.jb_delete)) {
                String a = this.jt_delete.getText();
                int i;
                if (a.equals("")) {
                    JOptionPane.showMessageDialog(this, "不能为空!!");
                } else {
                    try {
                       i= this.test.delete_Course(a);
                       if(i==1){
                           JOptionPane.showMessageDialog(this, "delete ok!!!");
                       }
                       else {
                           JOptionPane.showMessageDialog(this,"没有该信息记录!!");
                       }
                    } catch (Exception e) {
                        JOptionPane.showMessageDialog(this, "ERROR!!!");
                    }
                }
            }
            // update
            if(actionEvent.getSource().equals(this.jb_update)) {
                try {
                    String a = this.jt_update.getText();
                    String b = this.jt_update2.getText();
                    String c = this.jt_update3.getText();
    
                   if( this.test.update_Course_tea(a, b, c)==1){
                        JOptionPane.showMessageDialog(this, "update ok!!");
                    }
                    else {
                        JOptionPane.showMessageDialog(this,"检查输入!");
                    }
                } catch (Exception e) {
                     JOptionPane.showMessageDialog(this,"ERROR 检查输入信息");
                }
            }
            // select
            if(actionEvent.getSource().equals(this.jb_select)){
                for(int j=0;j<=18;j++){
                    this.table.setValueAt("",j,0);
                    this.table.setValueAt("",j,1);
                    this.table.setValueAt("",j,2);
                }
                try{
                    int i=0;
                    this.test.get_sql_connection();
                    this.test.ps=this.test.ct.prepareStatement("select * from Course");
                    this.test.rs= this.test.ps.executeQuery();
                    while (this.test.rs.next()){
                       this.table.setValueAt(this.test.rs.getString(1),i,0);
                       this.table.setValueAt(this.test.rs.getString(2),i,1);
                       this.table.setValueAt(this.test.rs.getString(3),i,2);
                        i++;
                    }
                }catch (Exception e){
                    JOptionPane.showMessageDialog(this,"检查输入信息!!!");
                }
                finally {
                    this.test.close();
                }
            }
            if(actionEvent.getSource().equals(this.jb_back)){
                //返回
                this.setVisible(false);
                this.windows.setVisible(true);
            }
        }
    }
    

    在这里插入图片描述

    五、程序讲解以及下载地址

    视频讲解
    下载地址具体的说明在README.md文件中

    六、参考文档及素材来源

    https://blog.csdn.net/wyf2017/java/article/details/78831744

    图片来源于wallheaven

    七、实验总结

    这个实验应用到了数据库的基本知识以及Java的一些内容,我个人觉得最大的问题是代码的重用率不高,不过自己写一个这样的程序收获还不小的。

    展开全文
  • 使用java编写数据库的底层实现,并且对编写的代码进行封装实现可以用实体类创建表和查询等操作
  • 数据库期末大作业,采用Mysql+java实现后端三层架构,前端使用html编写。
  • mysql + myeclipse,图书销售管理系统,含8种左右功能,内含详细实验报告+设计报告+展示用ppt 界面为java界面
  • 数据库大作业进程 一

    2020-05-03 20:08:29
    1 回顾 java GUI的基本用法 2 java 正则表达式 import java.util.regex.*; public class process { public static void main(String[] args) { String p ="[A-Za-z0-9]{4,9}"; Pattern r=Pattern.compi...

    说明

    使用的开发工具是idea 社区2019 .2.2 版

    实验进程

    1 回顾 java GUI的基本用法

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.regex.*;
    public class Login_in  extends JFrame implements ActionListener {
        public JLabel account;
        public JLabel password;
        public JButton button_login_in;
        public JTextField jt_account;
        public  JPasswordField jt_password;
        public JPanel jp1, jp2;
        public JLabel jl1;
        public ImageIcon Icon;
        protected  Windows windows=null;
        public Login_in() {
            this.jl1 = new JLabel();
            this.account = new JLabel("输入用户名");
            this.password = new JLabel("输入密码");
            this.button_login_in = new JButton("submit");
            this.Icon = new ImageIcon(getClass().getResource("/photo/4.jpg"));//使用的是getResource
            this.Icon.setImage(this.Icon.getImage().getScaledInstance(400, 400, Image.SCALE_DEFAULT));
            this.jl1.setIcon(this.Icon);
            this.button_login_in.addActionListener(this);
            this.jt_account = new JTextField(10);
            this.jt_password = new JPasswordField(10);
            this.jp1 = new JPanel();
            this.jp2 = new JPanel();
          
            this.setSize(400, 550);
            this.getContentPane().add(this.jl1);
            this.setLayout(new FlowLayout());
            this.setLocationRelativeTo(null);
            this.jp1.add(this.account);
            this.jp1.add(this.jt_account);
            this.getContentPane().add(this.jp1);
            this.jp2.add(this.password);
            this.jp2.add(this.jt_password);
            this.jp2.add(this.button_login_in);
            this.getContentPane().add(this.jp2);
            this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            this.setResizable(false);
            this.setVisible(true);
        }
        public static void main(String[] args) {
            new Login_in();
        }
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            String a, b;
            if (actionEvent.getSource().equals(this.button_login_in)) {
                a = this.jt_account.getText();
                b = this.jt_password.getText();
                Pattern p_account = Pattern.compile("[A-Za-z0-9]{4,9}");
                Pattern p_password = Pattern.compile("[A-Za-z0-9]{6,9}");
                Matcher m_account = p_account.matcher(a);
                if (m_account.find()) {
                    if(this.windows==null){
                        this.windows= new Windows(this);
                       
                    }
                    this.windows.setVisible(true);
                    this.setVisible(false);
                System.out.println("ok is login ");
                } else {
                 JOptionPane.showMessageDialog(this,"account is error!!");
                }
            }
        }
    }
    
    

    效果如图所示:
    在这里插入图片描述

    2 需要的使用 java 正则表达式的如下

    import java.util.regex.*;
    public class process {
        public static void main(String[] args) {
            String p ="[A-Za-z0-9]{4,9}";
           Pattern r=Pattern.compile(p);
           String  line="125";
           Matcher m =r.matcher(line);
           if(m.find()){
               System.out.println("ok is find !!!");
           }
           else {
               System.out.println(" no !!!");
           }
        }
    }
    
    

    这个类将会用来判断学生还是教师登录

    3 java Vector 相关的用法

    import java.util.Vector;
    
    public class VectorTest {
    
        public static void main(String[] args) {
            Vector<String >str = new Vector<>();
         str.add("a");
         str.add("b");
         for(int i=1;i<=str.size();i++){
             System.out.println(str.get(i-1));
         }
         str.clear();
         //清空所有的数据
        }
    }
    

    在存储数据库的数据将会用到vector
    4 使用的Md5 加密如下

    import java.io.UnsupportedEncodingException;
    import java.security.MessageDigest;
    import java.security.NoSuchAlgorithmException;
    import java.util.Base64;
    
    public class Md5  {
    
        public String getMd5_String(String a){
    
            String str = null;
            try{
                MessageDigest md=MessageDigest.getInstance("md5");
                byte[] bytes = md.digest(a.getBytes("UTF-8"));
                //得到了一个字节 计算摘要
    
                // a-z A-Z 0-9 / * 表示生成的string
                 str= Base64.getEncoder().encodeToString(bytes);
                System.out.println(str);
            }catch (NoSuchAlgorithmException e){
                e.printStackTrace();
            }
            catch (UnsupportedEncodingException e){
                e.printStackTrace();
                System.out.println("编码不支持");
            }
            return str;
        }
    }
    

    md5 将会用在存储用户的密码这个方面上。

    5 重写 DefaultTableModel 这个类

    import javax.swing.table.DefaultTableModel;
    
    public class MyDefaultTable extends DefaultTableModel {
        public MyDefaultTable(String [] str,int rows){
            super(str,rows);
        }
        public boolean  isCellEditable(int row,int col){
           return false;
        }
    }
    
    

    由此可见重写isCellEditable 方法改为false 即可,当然只有这一个构造方法。这个类是用于将表格组件可编辑改为不能编辑。
    在这里插入图片描述

    展开全文
  • 系统包含 大作业完整文档一份 2000字左右和源码和数据库java大作业;互联网开发大作业;软件开发大作业 ; 本系统是用JAVA编写的,运行环境也是在JAVA下,所用数据库为SQLServer2008数据库;系统包含:员工管理、...
  • java开发的图书管理系统:包含完整大作业报告一份(2000字)+源程序+Mysql数据库;也可以用来作为课程设计; 系统分为管理员和用户两个角色:管理员可以进行用户管理(增删查改)、图书管理(增删查改)、图书借出与...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 556
精华内容 222
关键字:

java数据库大作业

java 订阅