How To Return a Disconnected ADO Recordset From a Java COM Object (240086)



The information in this article applies to:

  • Microsoft Visual J++ 6.0
  • ActiveX Data Objects (ADO) 2.7
  • ActiveX Data Objects (ADO) 2.1
  • ActiveX Data Objects (ADO) 2.5
  • ActiveX Data Objects (ADO) 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:
  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:
    import com.ms.wfc.data.*;
    					
  3. 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();
    }
    
    					
  4. 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.
  5. Build the project. This step will also register the COM object.
  6. Use the object from a COM capable client.

Modification Type:MinorLast Reviewed:7/13/2004
Keywords:kbhowto KB240086