package com.example.leudaemialikeme.Utils;

import android.util.Log;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class DBUtils {

    private final static String driver = "com.mysql.jdbc.Driver";
    private final static String url = "jdbc:mysql://192.168.80.1:3306/leukemia?serverTimezone=UTC&useSSL=false&characterEncoding=utf8";

    private final static String username = "root";
    private final static String password = "123456";

    Connection conn=null;
    Statement st=null;
    ResultSet rs=null;

    static {
        try {
            Class.forName(driver);
            Log.v("mysql","加载驱动成功");
        } catch (ClassNotFoundException e) {
            Log.e("mysql","加载驱动错误");
        }
    }


    //2. 获取连接
    public static Connection getConnect() throws Exception {
        Connection conn=DriverManager.getConnection(url, username, password);
        Log.v("mysql","成功获取数据库");
        return conn;
    }

    //3. 释放连接资源

    public static void release(Connection conn, Statement st, ResultSet rs) throws Exception {
        if (rs != null) {
            rs.close();
        }
        if (st != null) {
            st.close();
        }
        if (conn != null) {
            conn.close();
        }

    }

}


