1.在(Hibernate5-常用方法)的基础上修改hibernate.cfg.xml配置文件,如下所示
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-configuration SYSTEM "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <!-- 可以从Hibernate核心jar(hibernate-core-x.x.x.Finall.jar) 文件中的or.hibernate.dialect包中找到相应的类,类的全名就是 --> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <!-- Assume test is the database name --> <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/b_shequ_two</property> <property name="hibernate.connection.username"> root </property> <property name="hibernate.connection.password"></property> <!-- create:每次都新创建,如果存在就删除 create-drop:创建新表,sessionFactory关闭,表会删除 update :表字段增加,会同步,字段减少不同步,数据改变会同步修改 --> <property name="hibernate.hbm2ddl.auto">update</property> <property name="hibernate.show_sql">true</property> <property name="hibernate.format_sql">true</property> <!-- 事务环境一个线程对一个事务 --> <property name="hibernate.current_session_context_class">thread</property> <!-- 使用c3p0数据源 --> <property name="hibernate.connection.provider_class"> org.hibernate.c3p0.internal.C3P0ConnectionProvider </property> <!-- List of XML mapping files --> <mapping resource="com/mycompany/demo/bean/Forum.hbm.xml"/> </session-factory> </hibernate-configuration>
2.在(Hibernate5-常用方法)的基础上在lib目录中添加c3p0jar包,如图所示
时间: 2024-10-14 14:02:46