|
hibernate.cfg.xml文件如下:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/Sample</property>
<property name="hibernate.connection.username">solomon</property>
<property name="hibernate.connection.password">1234</property>
<property name="hibernate.connection.pool.size">20</property>
<property name="hibernate.show_sql">true</property>
<property name="jdbc.fetch_size">50</property>
<property name="jdbc.batch_size">25</property>
<property name="jdbc.use_scrollable_resultset">false</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.useUnicode">true</property>
<property name="connection.characterEncoding">UTF-8</property>
<property name="hibernate.jdbc.batch_size">20</property>
<property name="hibernate.max_fetch_depth">1</property>
<mapping resource="sample/User.hbm.xml"/>
</session-factory>
</hibernate-configuration>
当执行session.beginTransaction();时,抛出异常:
Exception in thread "main" org.hibernate.exception.JDBCConnectionException: Cannot open connection
mysql服务已经打开,用户名和密码也没错,请问是mysql配置有问题还是hibernate.cfg.xml有问题? |
|