zoukankan      html  css  js  c++  java
  • 数据库程序设计第一天--数据库设计

    一、说在前面

      今天目标完成数据库的设计和数据库的链接

    二、任务完成度

    (1)建表

      

     

      information:人员居住信息表

      

     

      isolated_area:隔离地信息表

      

     

      login:登录信息表

      

     

      person:隔离人员信息表

      

     (2)建立链接

    package DBUtil;
    
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.Statement;
    
    public class DBUtil {
        //连接字符串
        public static String db_url = "jdbc:mysql://localhost:3306/isolation_management?&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC";
        //数据库用户名
        public static String db_user = "root";
        //数据库密码名
        public static String db_pass = "123456";
        
        //建立链接
        public static Connection getConn() {
            Connection conn=null;
            
            try {
                //驱动程序名
                Class.forName("com.mysql.cj.jdbc.Driver");
                //连接数据库
                conn=DriverManager.getConnection(db_url, db_user, db_pass);
            }catch (Exception e) {
                // TODO: handle exception
                e.printStackTrace();
            }
            
            
            return conn;
        }
        
        /**
         * 
         * @param state
         * @param conn
         */
        public static void close(Statement state, Connection conn) {
            if (state != null) {
                try {
                    state.close();
                } catch (Exception e) {
                    // TODO: handle exception
                    e.printStackTrace();
                }
            }
    
            if (conn != null) {
                try {
                    conn.close();
                } catch (Exception e) {
                    // TODO: handle exception
                    e.printStackTrace();
                }
            }
        }
        
        /**
         * 
         * @param rs
         * @param state
         * @param conn
         */
        //重载关闭方法
        public static void close (ResultSet rs, Statement state,Connection conn) {
            if(rs!=null) {
                try {
                    rs.close();
                }catch (Exception e) {
                    // TODO: handle exception
                    e.printStackTrace();
                }
            }
            
            if(state!=null) {
                try {
                    state.close();
                }catch (Exception e) {
                    // TODO: handle exception
                    e.printStackTrace();
                }
            }
            
            if(conn!=null) {
                try {
                    conn.close();
                }catch (Exception e) {
                    // TODO: handle exception
                    e.printStackTrace();
                }
            }
        }
        
    }
    DBUtil

     

     

      

  • 相关阅读:
    k8s资源编排
    虫师『软件测试』基础 与 测试杂谈
    虫师『性能测试』文章大汇总
    OMCS ——卓尔不群的网络语音视频聊天框架(跨平台)
    ESFramework ——成熟的C#网络通信框架(跨平台)
    2022.2 区块链的技术架构
    pytest文档80 内置 fixtures 之 cache 写入中文显示\u4e2d\u6587问题(用打补丁方式解决) 上海
    翻译校正
    Inside WCF Runtime
    Web Services Security
  • 原文地址:https://www.cnblogs.com/suanai/p/13540080.html
Copyright © 2011-2022 走看看