您的位置:首页 > 其它

润乾在hibernate中配置报表数据源

2016-11-22 11:19 441 查看
一、在hibernate框架中应用报表,可能会出现报表找不到数据源的错误。

二、在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获得
%>  
<report:html name=”report1″ contextName=”report_context”/> 

第二种现象解决办法:

微软帮助支持手册中解释是:
在手工事务模式 (AutoCommit=false)
下,如果使用直接 (SelectMethod=direct)
模式,当您尝试对使用 JDBC
驱动程序的SQL Server
数据库执行多个语句时,将会出现此问题。direct模式是该驱动程序的默认模式。设置为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中数据源配置如下:
<Conte
4000
xt 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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息