Jump to content
We've recently updated our Privacy Statement, available here ×

Subreports and JNDI


sdemelis

Recommended Posts

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

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/Tomcat

2- I created a simple java class where I access the JNDI pool and I deployed it on Jasper Server

3- In the subreport, instead of passing as connection expression the standard string

java.sql.DriverManager.getConnection ("jdbc:mysql://mydb", "user","pwd")

I used my custom class

myClass.myJNDIconnection("selectedDB")

 

Now when I execute the report, the connections are closed after 4 or 5 seconds.

Link to comment
Share on other sites

  • 1 year later...

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

  • 5 months later...

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...