Hibernate sqlserver2000与润乾报表集成中的数据源配置

(1)在hibernate框架中应用报表,可能会出现报表找不到数据源的错误。
       (2) 在Hibernate框架 sqlserver2000数据库中应用报表,在填报时可能会报错,错误提示:
[Microsoft][SQLServer 2000 Driver for JDBC]Can’t start a cloned connection while in manual transaction mode.


解决方案:


第一种现象解决办法:

       可以先在程序中获取hibernate的数据源,然后将数据源传递给报表标签。代码示例如下:
Connection conn = …..; //获得数据连接
Context ctx = new Context(); //使用report4.jar中的context对象
ctx.setDefDataSourceName(”mysql”); //设定数据源名
DataSourceConfig dsoc = new DataSourceConfig(DBTypes.MYSQL,true,”GBK”,”GBK”,false);//配置数据源
ctx.setDataSourceConfig(”mysql”,dsoc);
ctx.setConnection(”mysql”,conn); //连接给context对象
request.setAttribute(”report_context”,ctx); //report_context通过如下report:html中的contextname获得
–><%
   Connection conn = …..;                                                           //获得数据连接
   Context ctx = new Context();                                                       //使用report4.jar中的context对象
   ctx.setDefDataSourceName(”mysql”);                                                 //设定数据源名
   DataSourceConfig dsoc = new DataSourceConfig(DBTypes.MYSQL,true,”GBK”,”GBK”,false);//配置数据源
   ctx.setDataSourceConfig(”mysql”,dsoc);
   ctx.setConnection(”mysql”,conn);                                                   //连接给context对象
   request.setAttribute(”report_context”,ctx);                                        //report_context通过如下report:html中的contextname获得
%>  
<report:html name=”report1″ contextName=”report_context”/> 

 

第二种现象解决办法:
       设置为SelectMethod=Cursor        
       在tomcat中为报表配置一个数据源,并在url中加入 ;SelectMethod=Cursor        
       在hibernate配置文件中的数据库的url中也加入;SelectMethod=Cursor        
       以下是两个配置文件        
       hibernate.cfg.xml中的配置如下:       

 <session-factory>
  <property name=”connection.username”>sa</property>
  <property name=”connection.url”>
   jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=tylstj;SelectMethod=Cursor
  </property>
  <property name=”dialect”>
   org.hibernate.dialect.SQLServerDialect
  </property>
  <property name=”myeclipse.connection.profile”>sql2k</property>
  <property name=”connection.password”>sa</property>
  <property name=”connection.driver_class”>
   com.microsoft.jdbc.sqlserver.SQLServerDriver
  </property>

<mapping resource=”com/tylstj/pojo/Jl01.hbm.xml” />
  <!–其他pojo的映射文件略–>

 

在tomcat5.5.20中数据源配置如下:

<Context path=”/WebTylsj” docBase=”WebTylsj”
         privileged=”true” antiResourceLocking=”false” antiJARLocking=”false”>
   <Resource name = “sql2k” auth=”Container” type = “javax.sql.DataSource”
             maxActive=”5″ maxIdle=”2″ maxWait=”10000″ username=”sa” password=”sa”
             driverClassName=”com.microsoft.jdbc.sqlserver.SQLServerDriver” 
       url=”jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=tylstj;SelectMethod=Cursor”/>
</Context>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值