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>
2017-07-18
七月 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);//保存對象進入數據庫
}
}
2017-07-18
是不是驅動jar包導錯了。