hibernate.cfg.xml 配置 和数据库驱动

hibernate.cfg.xml

<session-factory>

<!--  jdbc db2
<property name="dialect">org.hibernate.dialect.DB2Dialect</property>
<property name="connection.driver_class">com.ibm.db2.jcc.DB2Driver</property>
<property name="myeclipse.connection.profile">com.ibm.db2.jcc.DB2Driver</property>
<property name="connection.url">jdbc:db2://localhost:50000/bbs</property>
<property name="connection.username">db2admin</property>
<property name="connection.password">123456</property>
-->

<!--  jdbc mysql
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/mos?useUnicode=true&amp;characterEncoding=UTF-8</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
-->




<!--  jndi db2
<property name="connection.datasource">java:comp/env/jdbc/bbs</property>
<property name="dialect">org.hibernate.dialect.DB2Dialect</property>
    -->
<!--  jndi mysql  -->
<property name="connection.datasource">java:comp/env/jdbc/mos</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
  

<property name="hbm2ddl.auto">update</property>
<property name="show_sql">false</property>

<mapping resource="com/icss/bbs/entities/Article.hbm.xml" />
<mapping resource="com/icss/bbs/entities/Category.hbm.xml" />
<mapping resource="com/icss/bbs/entities/Forum.hbm.xml" />
<mapping resource="com/icss/bbs/entities/User.hbm.xml" />

</session-factory>

server.xml
<!--bbs db2
<Context path="/bbs" reloadable="true" docBase="D:/Documents and Settings/Administrator/workspace/bbs/WebRoot"          workDir="${catalina.home}/work" crossContext="true">
              <Resource auth="Container" name="jdbc/bbs" type="javax.sql.DataSource"
               driverClassName="com.ibm.db2.jcc.DB2Driver"
                maxIdle="12" maxWait="5000" username="db2admin" password="123456" url="jdbc:db2://localhost:50000/bbs" maxActive="14"/>
        </Context>
-->


<!--bbs mysql -->

<Context path="/bbs" reloadable="true" docBase="D:/Documents and Settings/Administrator/workspace/bbs/WebRoot"          workDir="${catalina.home}/work" crossContext="true">
              <Resource auth="Container" name="jdbc/mos" type="javax.sql.DataSource"
               driverClassName="com.mysql.jdbc.Driver"
                maxIdle="12" maxWait="5000" username="root" password="root" url="jdbc:mysql://localhost:3306/mos?useUnicode=true&amp;characterEncoding=UTF-8" maxActive="14"/>
        </Context>

      </Host>

注意:
hibernate.cfg.xml的
<property name="connection.datasource">java:comp/env/jdbc/mos</property>
和 servler.xml
<Resource auth="Container" name="jdbc/mos" type="javax.sql.DataSource"
中的name要对应







你可能感兴趣的:(Hibernate,xml,mysql,jdbc,db2)