日期:2014-05-19  浏览次数:20499 次

用hibernate连接两个数据库
hibernate只是用来连接数据库的,没有其它操作,现在想从别的服务器上搜点数据,不会用hibernate配置了
开始是hibernate.cfg.xml
<?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= "hibernate.connection.url ">
jdbc:microsoft:sqlserver://*.*.*.11:1433;;SelectMethod=cursor;databaseName=**
</property>
<property   name= "hibernate.connection.driver_class ">
com.microsoft.jdbc.sqlserver.SQLServerDriver
</property>
<property   name= "hibernate.connection.username "> ** </property>
<property   name= "hibernate.connection.password "> ** </property>

<property   name= "hibernate.show_sql "> True </property>
<property   name= "hibernate.use_outer_join "> True </property>

<property   name= "c3p0.max_size "> 150 </property>
<property   name= "c3p0.min_size "> 20 </property>
<property   name= "c3p0.timeout "> 5000 </property>
<property   name= "c3p0.max_statements "> 200 </property>
<property   name= "c3p0.idle_test_period "> 3000 </property>
<property   name= "c3p0.acquire_increment "> 2 </property>
<property   name= "c3p0.validate   false "> false </property>

</session-factory>


</hibernate-configuration>
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
HibernateUtil.java


package   whwd.hibernate;


import   org.hibernate.*   ;
import   org.hibernate.cfg.*   ;
import   org.apache.log4j.Logger;
//import   org.apache.commons.logging.Log;
//import   org.apache.commons.logging.LogFactory;

public   class   HibernateUtil
{
        //private   static   Log   log   =   LogFactory.getLog(HibernateUtil.class)   ;
        private   static   Logger   log   =   Logger.getLogger( "HibernateUtil.class ");
        private   static   final   SessionFactory   sessionFactory;

        static
        {
                try
                {
            &nb