At the start of executing a report in jasperintelligence 1.1.0 I want to send a static
query to the database. The connection that sends this query should also be used to execute
the report!
My idea was to put the query in a bean(code) that links to the datasource:
applicationContext.xml:
I am not sure if the bean conSource can work as a datasource and this idea is possible to astablish with jasper intelligence without adjusting the source code. When i try executing the bean in jasperIntelligence it gives no method exceptions.
How can i get this working?
Any help would be greatly appriciated
thanks in advance,
Niels
query to the database. The connection that sends this query should also be used to execute
the report!
My idea was to put the query in a bean(code) that links to the datasource:
public class ConSourceImp implements ConSource{ Connection c; public DataSource datSourc; public void setDataSource(DataSource datSourc) { this.datSourc = datSourc; // use(); } public void use(){ try{ c = datSourc.getConnection(); //do something with the connection } catch(Exception e) { e.printStackTrace(); } } } |
applicationContext.xml:
<bean id="dataSource2" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName"> <value>oracle.jdbc.driver.OracleDriver</value> </property> <property name="url"> <value>jdbc:oracle:thin:@serverdb:1521:devdb</value> </property> <property name="username"> <value>username</value> </property> <property name="password"> <value>password</value> </property> </bean> <bean id="conSource" class="consource.ConSourceImp"> <property name="dataSource"> <ref bean="dataSource2"/> </property> </bean> |
I am not sure if the bean conSource can work as a datasource and this idea is possible to astablish with jasper intelligence without adjusting the source code. When i try executing the bean in jasperIntelligence it gives no method exceptions.
How can i get this working?
Any help would be greatly appriciated
thanks in advance,
Niels
5 Answers:
Posted on November 2, 2006 at 3:17am
The BeanDataSource is set up to do this.
The bean can be a class that implements:
The bean can be a class that implements:
Code: |
<br /> public interface ReportDataSourceService {<br /> <br /> void setReportParameterValues(Map parameterValues);<br /> <br /> void closeConnection();<br /> <br /> }</td></tr></tbody></table><br /> <br /> Create the bean definition in a file named something like applicationContext-myDataSource.xml and put it in /WEB-INF. Add the JAR with your class(es) into /WEB-INF/lib<br /> <br /> You can create a Bean data source in the repository with the name of your bean, and select this Bean data source as the data source for a report unit.<br /> <br /> <br /> <br /> Sherman<br /> JasperSoft |
Posted on November 3, 2006 at 9:56am
Thanks, im still confused how to call the bean from jasper intelligence. Should I call the DAO bean or create a transactionmanager bean and call that?
And how is the bean method used? Do i have to create a bean method and use it? or can I leave it blank.
Thanks in advance,
Niels
And how is the bean method used? Do i have to create a bean method and use it? or can I leave it blank.
Thanks in advance,
Niels
Posted on November 3, 2006 at 6:22pm
You can refer to the bean directly. There is no need to wrap it in a transaction manager.
If your bean implements ReportDataSourceService, you can leave the method name blank. If you have a bean that has methods that return ReportDataSourceServices, you can add the method name. The idea here was that you could have some common connection/data source related code in the bean and different result sets reflected in different methods.
Sherman
JasperSoft
If your bean implements ReportDataSourceService, you can leave the method name blank. If you have a bean that has methods that return ReportDataSourceServices, you can add the method name. The idea here was that you could have some common connection/data source related code in the bean and different result sets reflected in different methods.
Sherman
JasperSoft
Posted on November 6, 2006 at 9:00am
Then why it gives me the following error when i try to run a report in jasper intelligence:
applicationContext-myDatasource.xml:
consourceImp:
ReportDataSourceService interface:
How could i fix this?
thanks in advance,
niels
org.springframework.webflow.ActionExecutionException: Exception thrown executing [AnnotatedAction@1262f7c targetAction = com.jaspersoft.jasperserver.war.action.ViewReportAction@1f784d7, attributes = map[[empty]]] in state 'verifyData' of flow 'viewReportFlow'; nested exception is com.jaspersoft.jasperserver.api.JSException: Bean with name: conSource does not have method: org.springframework.webflow.ActionExecutionException: Exception thrown executing [AnnotatedAction@1262f7c targetAction = com.jaspersoft.jasperserver.war.action.ViewReportAction@1f784d7, attributes = map[[empty]]] in state 'verifyData' of flow 'viewReportFlow'; nested exception is com.jaspersoft.jasperserver.api.JSException: Bean with name: conSource does not have method: com.jaspersoft.jasperserver.api.JSException: Bean with name: conSource does not have method: etc.. |
applicationContext-myDatasource.xml:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="conSource" class="consource.ConSourceImp"> <property name="dataSource"> <ref bean="dataSource2"/> </property> </bean> <bean id="dataSource2" class="org.apache.commons.dbcp.BasicDataSource" singleton="false"> <property name="driverClassName"> <value>oracle.jdbc.driver.OracleDriver</value> </property> <property name="url"> <value>jdbc:oracle:thin:@localhost:1521:devdb</value> </property> <property name="username"> <value>user</value> </property> <property name="password"> <value>password</value> </property> </bean> </beans> |
consourceImp:
import com.jaspersoft.jasperserver.api.JSExceptionWrapper; import java.sql.Connection; import java.sql.SQLException; import java.util.Map; import javax.sql.DataSource; import net.sf.jasperreports.engine.JRParameter; public class ConSourceImp implements ReportDataSourceService{ Connection c; public DataSource datSourc; public void setDataSource(DataSource datSourc) { this.datSourc = datSourc; } public void closeConnection(){ try{ c.close(); } catch(Exception e){ e.printStackTrace(); } } public void use(){ try{ c = datSourc.getConnection(); //do something with the connection } catch(Exception e) { e.printStackTrace(); } } public void setReportParameterValues(Map parameterValues) { use(); try { c.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED); } catch (SQLException e) { e.printStackTrace(); throw new JSExceptionWrapper(e); } parameterValues.put(JRParameter.REPORT_CONNECTION, c); } } |
ReportDataSourceService interface:
import java.util.Map; public interface ReportDataSourceService { void setReportParameterValues(Map parameterValues); void closeConnection(); } |
How could i fix this?
thanks in advance,
niels