HOWTO: Return a Disconnected ADO Recordset From a Java COM Object

ID: Q240086


The information in this article applies to:
  • Microsoft Visual J++, version 6.0
  • ActiveX Data Objects (ADO), versions 2.1, 2.5


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:

  1. Create a new Java project packaged as a COM DLL called AdoObject.


  2. Add the following line of code to the Class1.java file:


  3. 
    import com.ms.wfc.data.*; 
  4. Add the following method to the default class (Class1):


  5. 
    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();
    }
     
  6. 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.


  7. Build the project. This step will also register the COM object.


  8. Use the object from a COM capable client.


Additional query words: ado disconnected recordset com object java

Keywords : kbVJ kbVJ600 kbGrpVCDB kbGrpMDAC kbDSupport kbADO250
Version : WINDOWS:2.1,2.5,6.0
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: January 11, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.