package cn.gyee.tamplate.util;

import java.sql.*;

/**
 * @ClassName : JdbcUtils
 * @Author : xieshengjie
 * @Date: 2021/1/15 17:14
 * @Description : jdbc工具
 */
public class JdbcUtils {
    private static String driver = null;
    private static String url = null;
    private static String username = null;
    private static String password = null;
    static {
        try{
            driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
            url = "jdbc:sqlserver://10.155.32.2:1433;databaseName=fdeam";
            username = "sa";
            password = "Gyee@321#!";
            //1.驱动只用加载一次
            Class.forName(driver);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    // 获取连接
    public static Connection getConnection() throws SQLException {
        return DriverManager.getConnection(url,username,password);
    }
    // 释放连接资源
    public static void relese(Connection conn, Statement st, ResultSet rs){
        if (rs!=null){
            try{
                rs.close();
            }catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if (st!=null){
            try{
                st.close();
            }catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if (conn!=null){
            try{
                conn.close();
            }catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
