我正在尝试使用cfg文件中的hibernate连接到mysql数据库
<?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">
com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">
jdbc:mysql://localhost:3306/test</property>
<property name="hibernate.connection.username">
root</property>
<property name="hibernate.connection.password">
root</property>
<property name="hibernate.connection.pool_size">
10</property>
<property name="show_sql">true</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">
update</property>
<!-- Mapping files -->
<mapping resource="Employee.hbm.xml" />
</session-factory>
</hibernate-configuration>
private static SessionFactory factory;
public static void main(String[] args) {
try {
factory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
System.err.println("Failed to create sessionFactory object." + ex);
ex.fillInStackTrace();
ex.printStackTrace();
throw new ExceptionInInitializerError(ex);
}
虽然我的连接字符串,用户名,密码是正确的,并且在基本的jdbc连接的其他项目中工作正常但是当我使用hibernate尝试它时我在控制台上收到此错误
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.hibernate.ManageEmployee.main(ManageEmployee.java:21)
Caused by: org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
at com.hibernate.ManageEmployee.main(ManageEmployee.java:19)
Caused by: org.dom4j.DocumentException: Connection refused: connect Nested exception: Connection refused: connect
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1481)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1425)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1411)
at com.hibernate.ManageEmployee.main(ManageEmployee.java:16)
是的,数据库服务器已启动并正在运行,但此hibernate应用程序的连接被拒绝
答案 0 :(得分:1)
问题是xml解析器正在尝试访问配置文件中指定的模式文件。您运行程序的方框可以访问互联网吗?
以下是一些其他信息: