为了账号安全,请及时绑定邮箱和手机立即绑定

为什么就是有问题呢?都是按着老师的步骤来的呀~~



public class StudentsTest {https://img1.sycdn.imooc.com//5cee39370001129f04100263.jpg private SessionFactory sessionFactory;

private Session session;

private Transaction transaction;

@Before

public void init(){

//创建配置对象

Configuration config = new Configuration().configure();

//创建服务注册对象(hibernate4.35之后该方法就不能再获取到实体信息了)

// ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();

ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(config.getProperties()).build();

//创建会话工厂

// sessionFactory = config.buildSessionFactory(serviceRegistry);

sessionFactory =new MetadataSources(serviceRegistry).buildMetadata().buildSessionFactory();

//会话对象

session = sessionFactory.openSession();

//开启事务

transaction = session.beginTransaction();

}

@After

public void destory(){

transaction.commit();//提交事务

session.close();//关闭会话

sessionFactory.close();//关闭会话工厂

}

@Test

public void testSaveStudents(){

//生成学生对象

Students s = new Students(1,"张三丰","男",new Date(),"武当山");

session.save(s);//保存对象进入数据库

}

}



<hibernate-configuration>

<session-factory>

<property name="connection.username">root</property>

<property name="connection.password">LOVEmm1314!</property>

<property name="connection.driver_class">com.mysql.jdbc.Driver</property>

<property name="connection.url">jdbc:mysql://114.116.152.128:3306/HYMAN_DEV?useUnicode=true&amp;characterEncoding=UTF-8&amp;serverTimezone=UTC</property>

<!-- <property name="dialect">org.hibernate.dialect.MYSQLDialect</property> -->

<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>

<property name="show_sql">true</property>

<property name="format_sql">true</property>

<property name="hbm2ddl.auto">create</property>

<mapping  resource="Students.hbm.xml"/>

</session-factory>

</hibernate-configuration>







五月 29, 2019 3:39:35 下午 org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>

INFO: HCANN000001: Hibernate Commons Annotations {4.0.5.Final}

五月 29, 2019 3:39:35 下午 org.hibernate.Version logVersion

INFO: HHH000412: Hibernate Core {4.3.11.Final}

五月 29, 2019 3:39:35 下午 org.hibernate.cfg.Environment <clinit>

INFO: HHH000206: hibernate.properties not found

五月 29, 2019 3:39:35 下午 org.hibernate.cfg.Environment buildBytecodeProvider

INFO: HHH000021: Bytecode provider name : javassist

五月 29, 2019 3:39:35 下午 org.hibernate.cfg.Configuration configure

INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml

五月 29, 2019 3:39:35 下午 org.hibernate.cfg.Configuration getConfigurationInputStream

INFO: HHH000040: Configuration resource: /hibernate.cfg.xml

五月 29, 2019 3:39:35 下午 org.hibernate.cfg.Configuration addResource

INFO: HHH000221: Reading mappings from resource: Students.hbm.xml

五月 29, 2019 3:39:35 下午 org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity

WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!

五月 29, 2019 3:39:35 下午 org.hibernate.cfg.Configuration doConfigure

INFO: HHH000041: Configured SessionFactory: null

五月 29, 2019 3:39:35 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure

WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!)

五月 29, 2019 3:39:35 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator

INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://114.116.152.128:3306/HYMAN_DEV?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC]

五月 29, 2019 3:39:35 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator

INFO: HHH000046: Connection properties: {user=root, password=****}

五月 29, 2019 3:39:35 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator

INFO: HHH000006: Autocommit mode: false

五月 29, 2019 3:39:35 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure

INFO: HHH000115: Hibernate connection pool size: 20 (min=1)

Wed May 29 15:39:35 GMT+08:00 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

五月 29, 2019 3:39:36 下午 org.hibernate.dialect.Dialect <init>

INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect


正在回答

1 回答

数据库的驱动配置出现错误:

旧版本的驱动配置:

<property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="url" value="

jdbc:mysql://Localhost:3306/student?userUnicode=true&amp;characterEncoding=UTF-8

"/>

 mysql8.0的驱动配置
jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/mybatis?characterEncoding=utf8&amp;useSSL=false&amp;serverTimezone=UTC&amp;rewriteBatchedStatements=true

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

为什么就是有问题呢?都是按着老师的步骤来的呀~~

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信