java6.17上午实训总结

1.本次实训的最终目的是为了编写一个完整的学生管理系统
为了之后码程序的时候能够有更加清晰的思路
首先,我们需要绘制一下结构图来了解学生管理系统应该实现那些功能java6.17上午实训总结_第1张图片
2.创建数据库,编写部分测试代码
(1).创建学生表student
java6.17上午实训总结_第2张图片
(2).创建用户表user
java6.17上午实训总结_第3张图片
(3).创建校表college
java6.17上午实训总结_第4张图片
(4).创建状态表status
java6.17上午实训总结_第5张图片
(5).四张表创建完成之后,我们为表插入简单的几条数据,如下:
java6.17上午实训总结_第6张图片
java6.17上午实训总结_第7张图片
java6.17上午实训总结_第8张图片
java6.17上午实训总结_第9张图片
好啦数据插入工作就简单的完成啦
3、在项目里创建文件夹help、images、lib
java6.17上午实训总结_第10张图片
4.实体类
java6.17上午实训总结_第11张图片
(1)创建学校Student实体类

package net.qt.student.bean;
/**
 * 包名:net.qt.student.bean
 * 类名:Student
 * 作者:谯婷
 * 日期:2019.6.17
 */
public class Student {
    private  String id;
    private  String name;
    private  String sex;
    private  String age;
    private  String department;
    private  String clazz;
    private String telephone;
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }

    public String getDepartment() {
        return department;
    }

    public void setDepartment(String department) {
        this.department = department;
    }

    public String getClazz() {
        return clazz;
    }

    public void setClazz(String clazz) {
        this.clazz = clazz;
    }

    public String getTelephone() {
        return telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }

    @Override
    public String toString() {
        return "Student{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                ", age='" + age + '\'' +
                ", department='" + department + '\'' +
                ", clazz='" + clazz + '\'' +
                ", telephone='" + telephone + '\'' +
                '}';
    }


}

(2)创建用户实体User类

package net.qt.student.bean;

/**
 * 包名:net.qt.student.bean
 * 类名:User
 * 作者:谯婷
 * 日期:2019.6.17
 */
public class User {
    private int id;
    private  String username;
    private String password;
    private String telephone;
    private String registerTime;
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getTelephone() {
        return telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }

    public String getRegisterTime() {
        return registerTime;
    }

    public void setRegisterTime(String registerTime) {
        this.registerTime = registerTime;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", telephone='" + telephone + '\'' +
                ", registerTime='" + registerTime + '\'' +
                '}';
    }


}

(3).创建学校实体College类

package net.qt.student.bean;
/**
 * 包名:net.qt.student.bean
 * 类名:College
 * 作者:谯婷
 * 日期:2019.6.17
 */
import com.sun.org.apache.xalan.internal.lib.ExsltDatetime;

public class College {
    private  int id;
    private String name;
    private  String president;
    private ExsltDatetime startTime;
    private String telephone;
    private String emial;
    private String address;
    private String profile;
    //通过ALT+Insert实现set+get方法
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPresident() {
        return president;
    }

    public void setPresident(String president) {
        this.president = president;
    }

    public ExsltDatetime getStartTime() {
        return startTime;
    }

    public void setStartTime(ExsltDatetime startTime) {
        this.startTime = startTime;
    }

    public String getTelephone() {
        return telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }

    public String getEmial() {
        return emial;
    }

    public void setEmial(String emial) {
        this.emial = emial;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getProfile() {
        return profile;
    }

    public void setProfile(String profile) {
        this.profile = profile;
    }


//alt+insert然后选择tostring
    @Override
    public String toString() {
        return "College{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", president='" + president + '\'' +
                ", startTime=" + startTime +
                ", telephone='" + telephone + '\'' +
                ", emial='" + emial + '\'' +
                ", address='" + address + '\'' +
                ", profile='" + profile + '\'' +
                '}';
    }
}

(4).创建状态实体Status类

package net.qt.student.bean;
/**
 * 包名:net.qt.student.bean
 * 类名:Status
 * 作者:谯婷
 * 日期:2019.6.17
 */
public class  Status{
    private int id;
    private  String college;
    private  String version;
    private String author;
    private String telephone;
    private String address;
    private String emils;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getCollege() {
        return college;
    }

    public void setCollege(String college) {
        this.college = college;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public String getTelephone() {
        return telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getEmils() {
        return emils;
    }

    public void setEmils(String emils) {
        this.emils = emils;
    }

    @Override
    public String toString() {
        return "Status{" +
                "id=" + id +
                ", college='" + college + '\'' +
                ", version='" + version + '\'' +
                ", author='" + author + '\'' +
                ", telephone='" + telephone + '\'' +
                ", address='" + address + '\'' +
                ", emils='" + emils + '\'' +
                '}';
    }


}

通过这几个实体类的创建,更加加深了我对alt+insert的方法的熟练度
java6.17上午实训总结_第12张图片java6.17上午实训总结_第13张图片
5、数据库连接管理类ConnectionManager
java6.17上午实训总结_第14张图片

package net.qt.student.dbutil;

import javax.swing.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * 包名:net.qt.student.dbutil
 * 类名:ConnectionManager
 * 作者:谯婷
 * 描述:数据库连接管理类
 * 日期:2019.6.17
 */
public class ConnectionManager {
    /**
     * 数据库驱动程序
     */
    private static final String DRIVER = "com.mysql.jdbc.Driver";
    /**
     * 数据库统一资源标识符
     */
    private  static final String URL = "jdbc:mysql://localhost:3306/student";
    /**
     * 数据库用户名
     */
    private static final String USERNAME = "root";
    /**
     * 数据库密码
     */
    private static final String PASSWORD = "1";
    /**
     * 私有化构造方法,拒绝实例化
     */
    private  ConnectionManager(){

    }

    /**
     * 获得数据库连接
     * @return 数据库连接对象
     */

    public static Connection getConnection(){
        //定义数据库连接
        Connection conn = null;
        try {
            //安装数据库驱动程序
            Class.forName(DRIVER);
            //获得数据库连接
            conn = DriverManager.getConnection(URL
            +"?useUnicode=true&characterEncoding=UTF8",USERNAME,PASSWORD);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        //返回数据库连接
        return conn;
    }
    /**
     * 关闭数据库连接
     * @param  conn
     */
    public static void closeConnection(Connection conn){
        //判断数据库连接是否为空
        if (conn != null){
            //判断数据库连接是否关闭
            try {
                if (!conn.isClosed()){
                    //关闭数据库连接
                    conn.close();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
    /**
     * 测试数据库连接是否成功
     * @param args
     */
    public static void main(String[] args){
        //获得数据库连接
        Connection conn = getConnection();
        //判断是否连接成功
        if (conn != null){
            JOptionPane.showMessageDialog(null,"恭喜,数据库连接成功");
        }else{
            //if ...else 中可以将行复制在内容使用ctrl+shift+光标键上下移动整行
            JOptionPane.showMessageDialog(null,"遗憾,数据库连接失败");
        }
        //关闭数据库
        closeConnection(conn);
    }
}

运行程序,测试数据库连接是否成功
java6.17上午实训总结_第15张图片
6.数据访问接口
java6.17上午实训总结_第16张图片
java6.17上午实训总结_第17张图片
java6.17上午实训总结_第18张图片
java6.17上午实训总结_第19张图片
java6.17上午实训总结_第20张图片
稍微小小的总结一下:第一天实训java,这样和老师一起做项目的感觉真好,有不懂的就可以问,这样以前上课没听懂的内容就又可以好好补一补了,接下来的几天一定要把这么乐观好奇的心态保持下去!加油哈哈哈~

你可能感兴趣的:(关于java的学习)