(2) MySQL database connection tool [database connection tool of Hibernate framework]

MySQL database connection tool
(1) MySQL database connection tool [the original JDBC packaged database connection tool]
(2) MySQL database connection tool [the database connection tool of the Hibernate framework]

(2) MySQL database connection tool [database connection tool of Hibernate framework]

HbnBusiness.java (database connection tool for Hibernate framework)

package com.hk.server.base;

import com.hk.server.model.Oper;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.query.Query;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;

/**
 * 类 Business 用于与数据库建立连接,组合 hibernate.cfg.xml 配置文件,使 hibernate 和数据库表建立访问机制。
 *
 * @author: shipleyleo
 * @create: 2023-05-19 18:51:59
 */
public class HbnBusiness {
   
    
    
    private static SessionFactory sf; // 建立会话库
    static {
   
    
    
        try {
   
    
    
            sf = new Configuration()
                    .configure()
                    .buildSessionFactory();
        } catch (Exception e) {
   
    
    
            e.printStackTrace();
        }
    }
    public static Session getSession() {
   
    
     // 获取会话
        Session s = null;
        if(sf != null) {
   
    
    
            s = 

Guess you like

Origin blog.csdn.net/Shipley_Leo/article/details/130833389