Hibernate数据源的配置(本文用到的环境eclipse 3.2+Myeclipse 5.5+tomcat 5.5+jdk 1.5+mysql 5.0) 1.修改Hibernate.cfg.xml配置文件如下 <session-factory> <property name="show_sql">true</property> <property name="dialect"> org.hibernate.dialect.MySQLDialect </property> <property name="connection.datasource"> java:/comp/env/datasource </property> <property name="session_factory_name">hibernate</property> <!--下面是映射文件--> <mapping resource="org/coffee/epet/hibernate/Petdiary.hbm.xml" /> <mapping resource="org/coffee/epet/hibernate/Petinfo.hbm.xml" /> <mapping resource="org/coffee/epet/hibernate/Pettype.hbm.xml" /> </session-factory> 2.找到tomcat目录 如:D:/Tomcat 5.5/conf,在这里修改context.xml配置文件如下 <!-- The contents of this file will be loaded for each web application --> <Context> <!-- Default set of monitored resources --> <WatchedResource>WEB-INF/web.xml</WatchedResource> <!-- Uncomment this to disable session persistence across Tomcat restarts --> <!-- <Manager pathname="" /> --> <!--下面配置数据源--> <Resource name="datasource" auth="Container" maxActive="50" maxIdle="40" maxWait="10000" type="javax.sql.DataSource" driverClassName="org.gjt.mm.mysql.Driver" url="jdbc:mysql://localhost:3306/epet?useUnicode=true&characterEncoding=UTF-8" username="root" password="coffee" /> </Context> 3.复制连接数据库要用的JAR包到 D:/Tomcat 5.5/common/lib 目录下 注意:tomcat6.0的目录结构和tomcat5.5不太一样,读者可以自己找一下lib目录和conf目录 至此,Hibernate已经可以使用数据源连接数据库了 2008-06-08 TasteCoffee
hibernate数据源的配置及其使用
最新推荐文章于 2018-06-11 18:01:42 发布