sdemelis Posted March 13, 2012 Share Posted March 13, 2012 Hello,is it possible to use a JNDI connection with a subreport? I need to use connections different from the main report and if I use a standard JDBC connection for the subreport, I have too many open connection on mySql. thanks Link to comment Share on other sites More sharing options...
sdemelis Posted March 14, 2012 Author Share Posted March 14, 2012 I found the solution. It's quite simple.....if you know what to do...I'll post it, maybe it could help someone else without loosing 2 days:1- I configured 2 JNDI connections on my JasperServer/Tomcat2- I created a simple java class where I access the JNDI pool and I deployed it on Jasper Server3- In the subreport, instead of passing as connection expression the standard stringjava.sql.DriverManager.getConnection ("jdbc:mysql://mydb", "user","pwd")I used my custom classmyClass.myJNDIconnection("selectedDB") Now when I execute the report, the connections are closed after 4 or 5 seconds. Link to comment Share on other sites More sharing options...
sdemelis Posted April 10, 2013 Author Share Posted April 10, 2013 As requested, here's the code of the jndi class: public static Connection getJNDIConnection(String db) throws Exception { String connString =""; InitialContext ctx = new InitialContext(); connString = "java:comp/env/jdbc/".concat(db); DataSource ds = (DataSource)ctx.lookup(connString); return ds.getConnection(); } The input string is the name of the jndi connection defined in Tomcat. Link to comment Share on other sites More sharing options...
nicolaifriis Posted October 4, 2013 Share Posted October 4, 2013 Connection expression on the sub-report (in the main report):javax.naming.InitialContext.doLookup("jdbc/jmydb").getConnection() Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now