Microsoft KB Archive/240086

= How To Return a Disconnected ADO Recordset From a Java COM Object =

Article ID: 240086

Article Last Modified on 7/13/2004

-

APPLIES TO


 * Microsoft Visual J++ 6.0 Standard Edition
 * Microsoft ActiveX Data Objects 2.7
 * Microsoft ActiveX Data Objects 2.1
 * Microsoft ActiveX Data Objects 2.5
 * Microsoft ActiveX Data Objects 2.6

-



This article was previously published under Q240086



SUMMARY
This article describes how to create a COM object in Java that returns a disconnected ADO recordset created without a connection. This ADO recordset can then be used in a scripting language, Microsoft Visual Basic or Microsoft Visual C++.

The com.ms.wfc.data.Recordset class is a wrapper class that contains an ADO Recordset COM object. It is necessary to return this internal ADO recordset from the Java COM object instead of the wrapper class. To return the internal ADO Recordset class, use the getDataSource method of the wrapper Recordset class.



MORE INFORMATION
To create a Java COM object that returns a disconnected recordset, use the following steps:

 Create a new Java project packaged as a COM DLL called AdoObject.  Add the following line of code to the Class1.java file: import com.ms.wfc.data.*;   Add the following method to the default class (Class1): public Object ReturnRecordset { Recordset rs = new Recordset; try { rs.setCursorLocation(AdoEnums.CursorLocation.CLIENT); Fields fields = rs.getFields; fields.append("id",AdoEnums.DataType.INTEGER,4,AdoEnums.FieldAttribute.UNSPECIFIED); fields.append("name",AdoEnums.DataType.CHAR,20,AdoEnums.FieldAttribute.UNSPECIFIED); rs.open; rs.addNew; fields.getItem("id").setInt(1); fields.getItem("name").setString("John"); rs.update; rs.addNew; fields.getItem("id").setInt(2); fields.getItem("name").setString("Paul"); rs.update; rs.moveFirst; }   catch (AdoException e)    { throw new com.ms.com.ComFailException(0x80004005); //E_FAIL }          return (Object) rs.getDataSource; }

 Make sure the default class (Class1) is exposed as a COM object. From the main menu select Project and then AdoObject Properties. Select the COM classes tab and make sure the checkbox next to Class1 is selected. Build the project. This step will also register the COM object. Use the object from a COM capable client.</ol>

Additional query words: ado disconnected recordset com object java

Keywords: kbhowto KB240086

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.