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  com.crystaldecisions.sdk.occa.report.application.ReportClientDocument, 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:

import com.crystaldecisions.sdk.occa.report.application.ReportClientDocument;

ReportClientDocument rpt =  new ReportClientDocument();

        rpt.open(reportPath+fileName, 0);

        Fields fields = null;

       

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

       

         PropertyBag innerProp = connInfo.getAttributes();

            innerProp.clear();

           

            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=`");

       

            connInfo.setAttributes(innerProp);

            connInfo.setPassword(DBConnect.getPassword());

            connInfo.setUserName(DBConnect.getUsername());

               

               

       

       

        int replaceParams = DBOptions._ignoreCurrentTableQualifiers + DBOptions._doNotVerifyDB;

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

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