我在Java EE中有一个动态Web项目。 当我在Hibernate中使用“auto create database”时,编译不会给出任何例外警告,也不会创建数据库。
实际上,我已经将“wampserver”的端口80更改为81,因为IIS服务器已经在80上。在我的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="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:81/DB_TRANSPORT_CARGAISON</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">false</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2dll.auto">create</property>
<mapping resource="dao/Cargaison.hbm.xml"/>
<mapping resource="dao/Marchandise.hbm.xml"/>
</session-factory>
</hibernate-configuration>
为什么这不起作用?
答案 0 :(得分:0)
您设置为81的端口80是wamp的Web服务器的端口(即Apache的端口,wamp中的 a )。您必须在JDBC URL中指定的是MySQL数据库服务器的端口:wamp中的 m 。
我的猜测是你让它保持默认值,所以不指定任何端口应该可以正常工作:
jdbc:mysql://localhost/DB_TRANSPORT_CARGAISON