1 参考 Tomcat 配置文件 配好 Tomcat 数据源 2 修改 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" > <!-- Generated by MyEclipse Hibernate Tools. --> < hibernate-configuration > < session-factory > <property name="connection.useUnicode">true</property> <property name="connection.characterEncoding">gb2312</property> <!— 只配这一句就可以了的 用户名密码等等其他参数全部不用配了的 -- > <property name="connection.datasource">java:comp/env/jdbc/mysql</property> < property name = "dialect" > org.hibernate.dialect.MySQLDialect </ property > < mapping resource = "com/test/Hibernate/orm/User.hbm.xml" /> </ session-factory > </ hibernate-configuration > 3 测试用例