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

calling DriverManager#getConnection

org.hibernate.exception.JDBCConnectionException: Error calling DriverManager#getConnection

at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:132)

at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator$1$1.convert(BasicConnectionCreator.java:118)

这是我的hibernate.cfg.xml代码:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-configuration PUBLIC

"-//Hibernate/Hibernate Configuration DTD 3.0//EN"

"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

<session-factory>

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

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

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

<property name="connection.url"><![CDATA[jdbc:mysql://127.0.0.1:3306/hibernate?useUnicode=true&characterEncoding=UTF-8]]></property>

<property name="dialect">org.hibernate.dialect.MySQLDialect</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>


正在回答

2 回答

七月 18, 2017 10:33:01 下午 org.hibernate.annotations.common.Version <clinit>

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

七月 18, 2017 10:33:01 下午 org.hibernate.Version logVersion

INFO: HHH000412: Hibernate Core {4.3.8.Final}

七月 18, 2017 10:33:01 下午 org.hibernate.cfg.Environment <clinit>

INFO: HHH000206: hibernate.properties not found

七月 18, 2017 10:33:01 下午 org.hibernate.cfg.Environment buildBytecodeProvider

INFO: HHH000021: Bytecode provider name : javassist

七月 18, 2017 10:33:02 下午 org.hibernate.cfg.Configuration configure

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

七月 18, 2017 10:33:02 下午 org.hibernate.cfg.Configuration getConfigurationInputStream

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

七月 18, 2017 10:33:02 下午 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!

七月 18, 2017 10:33:02 下午 org.hibernate.cfg.Configuration addResource

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

七月 18, 2017 10:33:02 下午 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!

七月 18, 2017 10:33:02 下午 org.hibernate.cfg.Configuration doConfigure

INFO: HHH000041: Configured SessionFactory: null

七月 18, 2017 10:33:02 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure

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

七月 18, 2017 10:33:02 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator

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

七月 18, 2017 10:33:02 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator

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

七月 18, 2017 10:33:02 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator

INFO: HHH000006: Autocommit mode: false

七月 18, 2017 10:33:02 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure

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

我的xml文件:、



import java.util.Date;


import org.hibernate.Session;

import org.hibernate.SessionFactory;

import org.hibernate.Transaction;

import org.hibernate.boot.registry.StandardServiceRegistryBuilder;

import org.hibernate.cfg.Configuration;

import org.hibernate.service.ServiceRegistry;

import org.hibernate.service.ServiceRegistryBuilder;

import org.junit.After;

import org.junit.Before;

import org.junit.Test;



public class StudentsTest {

private SessionFactory sessionFactory;

private Session session;

private Transaction transaction; 

@Before

public void init(){

//创建配置对象

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

//创建服务注册对象

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

ServiceRegistry serviceRegistry = 

new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();

//创建sessionFactory对象

sessionFactory = config.buildSessionFactory(serviceRegistry);

//创建会话对象

session = sessionFactory.openSession();

//开启事务

transaction = session.beginTransaction();

}

@After

public void destroy(){

transaction.commit();

session.close();

sessionFactory.close();

}

@Test

public void testSaveStudents(){

//生成学生对象

Students s = new Students(1,"Groves","woman",new Date(),"NYC");

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

}


}


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

调皮的魔法少女李狗蛋儿 提问者

test文件
2017-07-18 回复 有任何疑惑可以回复我~

是不是驱动jar包导错了。

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

举报

0/150
提交
取消
Hibernate初探之单表映射
  • 参与学习       74810    人
  • 解答问题       793    个

Java持久化框架Hibernate入门教程,掌握Hibernate基本概念

进入课程

calling DriverManager#getConnection

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