cancel
Showing results for 
Search instead for 
Did you mean: 

Connecting to an oracle database questions

Former Member
0 Kudos

<p>Our current solution to connecting to our oracle database uses the following code:</p><p> ReportClientDocument clientDoc = new ReportClientDocument;</p><p> java.sql.ResultSet rs = fetchResultSet(driverName, connectStr, userName, password, <u>query</u>);</p><p> clientDoc.getDatabaseController().setDataSource(rs, <u>tableName</u>,tableName+"_ResultSet"); </p><p>The code for subreports is very similar, but isn&#39;t necessary for my question. The problem w/ this approach is we have to define the SQL query and the table name in the JSP, which we shouldn&#39;t have to do considering both of these are stored in the report. Any changes to the reports&#39; sql would then require someone to edit the jsp, which is just bad. </p><p>I have been reading up on the ConnectionInfo and ConnectionInfos classes (nice naming convention btw) and the CrystalReportViewer.setDataBaseLogonInfos() method, and I believe a solution may lie here. The problem is the tutorials on using the ConnectionInfo class assume the database name is stored in the report, and we do not want to assume this. We are developing our reports to be used by our customers, who may name their database whatever they want so long as the tables inside it are what we specify. Because of this assumption, I have yet to find a good explanation of how to use the setAttributes(PropertyBag) method which is the only I have seen to specify the database name (within a connection string). I have examples of it, but nothing that defines the key/value pairs required in the PropertyBag to create a connection to an oracle database. </p><p>Is there some documentation on the key/value pairs needed by the PropertyBag? Also, if there is another (easier) solution I am overlooking then please let me know, thanks.</p><p>-Sam Morehouse</p><p>HBF Group, Inc </p><p>&nbsp;</p>

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

<p>got it working, here&#39;s some sample code. </p><p>&nbsp;</p><p><%<br /> try{<br /> ReportClientDocument clientDoc = new ReportClientDocument();<br /> clientDoc.open(reportName, 0);<br /> <br /> ConnectionInfos connInfos = new ConnectionInfos();<br /> IConnectionInfo iConnInfo = new ConnectionInfo();<br /><br /> PropertyBag bag = new PropertyBag();<br /> bag.put("Database Class Name",driverName); // "oracle.jdbc.driver.OracleDriver"<br /> bag.put("Connection URL",connectStr); // "jdbc:oracle:thin:@dbName:1521:sid"<br /> <br /> PropertyBag pb = new PropertyBag();<br /> pb.put(PropertyBagHelper.CONNINFO_CRQE_LOGONPROPERTIES ,bag);<br /> pb.put(PropertyBagHelper.CONNINFO_DATABASE_DLL ,"crdb_jdbc.dll");<br /> iConnInfo.setAttributes(bag);<br /> <br /> iConnInfo.setUserName(userName);<br /> iConnInfo.setPassword(password); <br /> <br /> iConnInfo.setAttributes(pb);<br /> <br /> connInfos.add(iConnInfo);<br /> session.setAttribute(reportName, clientDoc);<br /> session.setAttribute("reportSource", clientDoc.getReportSource());<br /><br /> //Setup viewer. Only going to include the relevant line, the rest can be found</p><p> //elsewhere.<br /></p><p> CrystalReportViewer oCrystalReportViewer = new CrystalReportViewer(); oCrystalReportViewer.setDatabaseLogonInfos(connInfos); } </p><p>catch(ReportSDKExceptionBase exc)%></p>