MyEclipse连接数据库问题

kristi123 2018-04-06 04:38:19
MyEclipse连接数据库一直报错:
2018-4-6 16:19:25 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.0.0.CR4}
2018-4-6 16:19:25 org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
2018-4-6 16:19:25 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
2018-4-6 16:19:25 org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity
WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-configuration. Use namespace http://www.hibernate.org/dtd/hibernate-configuration instead. Support for obsolete DTD/XSD namespaces may be removed at any time.
2018-4-6 16:19:25 org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.0.Final}
2018-4-6 16:19:25 org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity
WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-mapping. Use namespace http://www.hibernate.org/dtd/hibernate-mapping instead. Support for obsolete DTD/XSD namespaces may be removed at any time.
2018-4-6 16:19:27 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!)
2018-4-6 16:19:27 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost/hibernate]
2018-4-6 16:19:27 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000046: Connection properties: {user=root, password=****}
2018-4-6 16:19:27 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000006: Autocommit mode: false
2018-4-6 16:19:27 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
2018-4-6 16:19:28 org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
2018-4-6 16:19:28 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop
INFO: HHH000030: Cleaning up connection pool [jdbc:mysql://localhost/hibernate]

配置文件设置是:
<?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="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/hibernate</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>

<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

<property name="show_sql">true</property>

<mapping resource="hibernate/model/Student.hbm.xml"/>
</session-factory>

</hibernate-configuration>

看显示的有hibernate.properties not found问题,但已经配置了properties.cfg.xml文件,且是配在src目录下,为何还会出现这个错误

其中项目层级配置是:




对象类是:
package hibernate.model;

public class Student {
private int id;
private String name;
private int age;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}


}

映射文件是:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">


<hibernate-mapping package="hibernate.model">
<class name="Student">
<id name="id" ></id>
<property name="name" ></property>
<property name="age" ></property>
</class>

</hibernate-mapping>


测试类是:
package Test;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import hibernate.model.Student;

public class StudentTest {
public static void main(String[] args) {
Student s = new Student();
s.setId(1);
s.setName("zhangsan");
s.setAge(8);

Configuration cfg = new Configuration().configure();
SessionFactory sf=cfg.buildSessionFactory();
Session session=sf.openSession();

session.beginTransaction();
session.save(s);
session.getTransaction();

session.close();
sf.close();
}
}


...全文
510 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
kristi123 2018-04-09
  • 打赏
  • 举报
回复
引用 1 楼 jdsnhan 的回复:
配置文件的路径不正确
我的配置文件是在src目录下啊
jdsnhan 2018-04-08
  • 打赏
  • 举报
回复
配置文件的路径不正确
kristi123 2018-04-08
  • 打赏
  • 举报
回复
hibernate.cfg.xml在创建项目时,直接在src目录下创建,不是吗?

我建立的配置文件在src目录下啊

58,454

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧