我的hibernate是3.6.7
mysql是5.1.59
jdbc是5.1.18
配置文件:
<hibernate-configuration>
<session-factory name="foo">
<property name="hibernate.connection.url">jdbc:mysql:localhost/hibernate_first</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">123456</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.show_sql">true</property> </session-factory>
</hibernate-configuration>
运行
Configuration cfg = new Configuration().configure();
SchemaExport export = new SchemaExport(cfg);
export.create(true, true);报错:
63 [main] INFO org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.2.0.Final
78 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.6.7.Final
78 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
78 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
78 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
110 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
110 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
156 [main] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: foo
172 [main] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.MySQLDialect
203 [main] INFO org.hibernate.cfg.Configuration - Hibernate Validator not found: ignoring
203 [main] INFO org.hibernate.tool.hbm2ddl.SchemaExport - Running hbm2ddl schema export
203 [main] INFO org.hibernate.tool.hbm2ddl.SchemaExport - exporting generated schema to database
203 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
203 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 20
203 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - autocommit mode: false
219 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql:localhost/hibernate_first
219 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=root, password=****}
219 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaExport - schema export unsuccessful
java.sql.SQLException: No suitable driver found for jdbc:mysql:localhost/hibernate_first
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:133)
at org.hibernate.tool.hbm2ddl.ManagedProviderConnectionHelper.prepare(ManagedProviderConnectionHelper.java:52)
at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:263)
at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:219)
at first.ExportDB.main(ExportDB.java:16)

解决方案 »

  1.   

    另外,我用log4j配置的输出加了slf4j-simple-1.6.3
      

  2.   

    property name="hibernate.connection.url">jdbc:mysql:localhost:3306/hibernate_first</property>
      

  3.   

    No suitable driver found for jdbc:mysql:localhost:3306/hibernate_first
      

  4.   

    jdbc:mysql://localhost:3306/hibernate_first
      

  5.   

    找到了,忘了写mapping resource了
      

  6.   

    我使用Hibernate时能成功注册jdbc驱动程序,但是Tomcat说无法unregistered it 当关闭的时候。