润乾在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>
二、在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>
相关文章推荐
- Hibernate sqlserver2000与润乾报表集成中的数据源配置
- 润乾报表在hibernate中配置报表数据源
- ssh框架中,hibernate配置多个数据源的报表模块
- 润乾报表在proxool应用下的数据源配置
- 润乾报表在websphere8部署配置数据源报错 java.sql.SQLException: 调用中无效的参数DSRA0010E: SQL 状态 = null,错误代码 = 17,433 而失败
- Hibernate配置数据源,数据库连接池
- hibernate 数据源配置
- Hibernate与Spring多数据源的配置
- Spring+Hibernate如何配置数据源(Struts Spring Hibernate (SSH) 整合实例)
- Hibernate 与 Spring 多数据源的配置
- 用Spring管理Hibernate连接多个数据源配置文件
- Spring+Hibernate配置多数据源
- Hibernate配置多个数据源
- Spring+Hibernate配置多数据源
- Hibernate.cfg.xml 数据源配置
- Hibernate 与 Spring 多数据源的配置
- 润乾配置数据源的两种方式
- 如何在spring配置多个Hibernate数据源链接
- Spring包装下Hibernate配置多个数据源
- Hibernate配置数据源、Hibernate数据库连接池