三月十四日结对

合作对象:李佳岳

今天探讨了一下数据库的结构,并把相应的地铁线路数据输入到了数据库,目前只有三条路线。

 

并且连接了数据库

package dbutil;
 
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
 
public class DButil {
    public static String url = "jdbc:mysql://localhost:3306/ditiexianlu?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8";
    public static String user = "root";
    public static String password = "NN06280055";
    public static String driver = "com.mysql.cj.jdbc.Driver";
    public static Connection getConn() {
        Connection conn = null;
        try {
            Class.forName(driver);
 
             // 连续数据库
            conn = DriverManager.getConnection(url, user, password);
              
               
 
        } catch (Exception e) {
            e.printStackTrace();
        }
        return conn;
    }
     
    public static void close(Statement state, Connection conn) {
        if(state!=null) {
            try {
                state.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if(conn!=null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
     
    public static void close(ResultSet rs, Statement state, Connection conn) {
        if(rs!=null) {
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if(state!=null) {
            try {
                state.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if(conn!=null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}

以及建立了相应的bean包以及无参数的构造函数。

package bean;
 
public class Bean {
    private String name;
    private int number;
    private String nearline;
     
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getNumber() {
        return number;
    }
    public void setNumber(int number) {
        this.number = number;
    }
    public String getNearline() {
        return nearline;
    }
    public void setNearline(String nearline) {
        this.nearline = nearline;
    }
     
    public Bean() {};
    public Bean(String name,int number,String nearline)
    {
        this.name=name;
        this.number=number;
        this.nearline=nearline;
    }
     
}

 

 

posted @ 2023-03-14 21:23  布吉岛???  阅读(9)  评论(0编辑  收藏  举报