Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

How to switch database connection at runtime in crystal reports using java swing

Please help. I am developing a swing application that can open reports made using crystal reports xi. What Im trying to do is to open a report and pass the connection info to that report so that I can dynamically change the database of the report. But for some reason it is not working and the report still produces the information from the database that it was initially set up. Can someone please tell me what I did wrong?  Btw when I try using, I get a server not found error. But when I try to use import com.crystaldecisions.reports.sdk.ReportClientDocument; It's not working. I am not sure what a report server is and I dont think I set it up on my computer. Please help. Here is my code:


ReportClientDocument rpt =  new ReportClientDocument();, 0);

        Fields fields = null;


        IConnectionInfo connInfo = rpt.getDatabaseController().getConnectionInfos(null).getConnectionInfo(0);


         PropertyBag innerProp = connInfo.getAttributes();



            PropertyBag propertyBag = new PropertyBag();

            propertyBag.put("Server Type", "JDBC (JNDI)");

            propertyBag.put("Database DLL", "crdb_jdbc.dll");

            propertyBag.put("Database Class Name", "com.mysql.jdbc.Driver");

            propertyBag.put("Use JDBC", "true");

            propertyBag.put("Server Name", DBConnect.getServer());

            propertyBag.put("Generic JDBC Driver Behavior", "No");

            propertyBag.put("URI", "!com.mysql.jdbc.Driver!jdbc:mysql://"+DBConnect.getServer()+":"+DBConnect.getPort()+"/"+DBConnect.getDatabase()+"!ServerType=29!QuoteChar=`");









        int replaceParams = DBOptions._ignoreCurrentTableQualifiers + DBOptions._doNotVerifyDB;

        rpt.getDatabaseController().replaceConnection(rpt.getDatabaseController().getConnectionInfos(null).getConnectionInfo(0), connInfo, fields, replaceParams);

Former Member
Not what you were looking for? View more on this topic or Ask a question