Jump to content
Changes to the Jaspersoft community edition download ×

Way to get Connection in Scriptlet?


2004 IR Help

Recommended Posts

By: geraldine84 - geraldine84

Way to get Connection in Scriptlet?

2005-11-08 03:21

Hello,

 

I'm starting on jasperreports. I would like to get the Connection in the scriptlet, because I need it. But I don't want to get informations about connection, and re-create a connection in the scriptlet. I really want the scriptlet to get the Connection (Object).

 

Thanks a lot,

 

G鲡ldine.

 

 

 

 

By: Teodor Danciu - teodord

RE: Way to get Connection in Scriptlet?

2005-11-08 07:54

 

Hi,

 

Inside the scriptlet implementation you have access

to a method called getParameterValue().

 

Get the connection object with something like:

 

getParameterValue(JRParameter.REPORT_CONNECTION)

 

I hope this helps.

Teodor

 

 

 

 

 

By: geraldine84 - geraldine84

RE: Way to get Connection in Scriptlet?

2005-11-08 23:36

Hello,

 

here is a simple method in the scriptlet. This works fine, there is no problems.

 

public String getConnection(){

try {

connection=(Connection) super.getParameterValue(JRParameter.REPORT_CONNECTION);

} catch (JRScriptletException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return connection.toString();

}

 

But I would like to get the connection in the default constructor, like this : (with a private field : private Connection connection=null; )

 

public connexionScriptlet(){

try {

connection=(Connection) super.getParameterValue(JRParameter.REPORT_CONNECTION);

} catch (JRScriptletException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

 

and I get this error :

 

java.lang.NullPointerException

at net.sf.jasperreports.engine.JRAbstractScriptlet.getParameterValue(JRAbstractScriptlet.java:88)

at connexionScriptlet.<init>(connexionScriptlet.java:15)

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)

at java.lang.reflect.Constructor.newInstance(Constructor.java:274)

at java.lang.Class.newInstance0(Class.java:308)

at java.lang.Class.newInstance(Class.java:261)

at net.sf.jasperreports.engine.fill.JRBaseFiller.createScriptlet(JRBaseFiller.java:1034)

at net.sf.jasperreports.engine.fill.JRBaseFiller.<init>(JRBaseFiller.java:590)

at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:93)

at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:75)

at net.sf.jasperreports.engine.fill.JRFiller.createFiller(JRFiller.java:113)

at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:57)

at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:247)

at Scriptlet.main(Scriptlet.java:27)

 

NESTED BY :

java.lang.NullPointerException

at net.sf.jasperreports.engine.JRAbstractScriptlet.getParameterValue(JRAbstractScriptlet.java:88)

at connexionScriptlet.<init>(connexionScriptlet.java:15)

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)

at java.lang.reflect.Constructor.newInstance(Constructor.java:274)

at java.lang.Class.newInstance0(Class.java:308)

at java.lang.Class.newInstance(Class.java:261)

at net.sf.jasperreports.engine.fill.JRBaseFiller.createScriptlet(JRBaseFiller.java:1034)

at net.sf.jasperreports.engine.fill.JRBaseFiller.<init>(JRBaseFiller.java:590)

at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:93)

at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:75)

at net.sf.jasperreports.engine.fill.JRFiller.createFiller(JRFiller.java:113)

at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:57)

at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:247)

at Scriptlet.main(Scriptlet.java:27)

 

NESTED BY :

net.sf.jasperreports.engine.JRException: Error creating scriptlet class instance : connexionScriptlet

at net.sf.jasperreports.engine.fill.JRBaseFiller.createScriptlet(JRBaseFiller.java:1038)

at net.sf.jasperreports.engine.fill.JRBaseFiller.<init>(JRBaseFiller.java:590)

at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:93)

at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:75)

at net.sf.jasperreports.engine.fill.JRFiller.createFiller(JRFiller.java:113)

at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:57)

at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:247)

at Scriptlet.main(Scriptlet.java:27)

Caused by: java.lang.NullPointerException

at net.sf.jasperreports.engine.JRAbstractScriptlet.getParameterValue(JRAbstractScriptlet.java:88)

at connexionScriptlet.<init>(connexionScriptlet.java:15)

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)

at java.lang.reflect.Constructor.newInstance(Constructor.java:274)

at java.lang.Class.newInstance0(Class.java:308)

at java.lang.Class.newInstance(Class.java:261)

at net.sf.jasperreports.engine.fill.JRBaseFiller.createScriptlet(JRBaseFiller.java:1034)

... 7 more

 

I don't understand why....

 

Thanks a lot,

 

G鲡ldine

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...