三月 29, 2017 10:33:16 下午 org.hibernate.annotations.common.Version
INFO: HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
三月 29, 2017 10:33:16 下午 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.2.2.Final}
三月 29, 2017 10:33:16 下午 org.hibernate.cfg.Environment
INFO: HHH000206: hibernate.properties not found
三月 29, 2017 10:33:16 下午 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
三月 29, 2017 10:33:16 下午 org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
三月 29, 2017 10:33:16 下午 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.password">1995</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/hibernate?characterEncoding=utf8&&serverTimezone=UTC</property>
<!-- <property name="jdbcUrl"> jdbc:mysql://localhost:3306/hibernate?characterEncoding=utf8&serverTimezone=UTC</property> -->
<property name="hibernate.current_session_context_class">thread</property>
<!-- 是否在控制台打印sql -->
<property name="show_sql">true</property>
<!-- 是否对sql进行格式化 -->
<property name="format_sql">true</property>
<!-- 指定自动生成数据表的策略 -->
<property name="hbm2ddl">update</property>
<!-- 指定关联的hbm.xml -->
<mapping resource="entity/Users.hbm.xml"/>
</session-factory>
</hibernate-configuration>
public class TestUsers {
@Test
public void testSchemaExport(){
Configuration configuration = new Configuration().configure();
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder()
.applySettings(configuration.getProperties()).buildServiceRegistry();
SessionFactory sf = configuration.buildSessionFactory(serviceRegistry);
Session session = sf.openSession();
// Transaction trans = session.beginTransaction();
//
// Users user = new Users("1","2","3");
// session.save(user);
//
// trans.commit();
SchemaExport export = new SchemaExport(configuration);
export.create(true,true);
session.close();
sf.close();
}
}
你的URL数据库名称为什么这么奇葩
应该是URL错了,端口号可以不要,三斜杠后面写你的数据库名称,还有看看你的数据库是否已经启动
你把错误贴全一点;
检查下你的xml文件位置放的对不对