Initial commit

This commit is contained in:
troggan
2004-10-17 18:36:38 +00:00
commit e9424dbca6
124 changed files with 15306 additions and 0 deletions

View File

@@ -0,0 +1,88 @@
- ADO Wrapper for JACOB - Copyright 1999, Dan Adler
This sample shows how to generate more strongly typed wrapper classes
for the JACOB automation classes. These are pure java classes which
extend com.jacob.com.Dispatch and delegate all the methods to the
unedrlying IDispatch pointer. This methodology is similar to the way
MFC does automation wrappers, rather than using the @com directives
to invisibly delegate the calls, as the Microsoft VM does.
The ADO wrappers in this directory are not a part of the JACOB
distribution, however, they demonstrate the preferred way to create
wrappers around the core functionality. The wrappers included here are
not a complete set, but they could easily be extended to provide all
the functionality of the com.ms.wfc.data classes.
The code in test.java demonstrates two ways to get a Recordset
from SQL Server. In this case, I query for the authors in the 'pubs'
database once by opening a Recordset object directly, and once by
using the Command and Connection objects. The same code, using the WFC
wrappers can be found in ms\testms.java in case you want to compare
the performace. You can run the test.java demo in the MS VM as well.
The constructor of the wrapper is used to create an instance.
For example, the user can write:
Connection c = new Connection();
The code for the Connection constructor is shown here:
public Connection()
{
super("ADODB.Connection");
}
it simply delegates to the com.jacob.com.Dispatch constructor which
takes a ProgID.
Since I don't have a tool like JACTIVEX yet to create the wrappers
automatically from the type library, I created them by hand by using
the JACTIVEX'ed version as a starting point, and replacing the @com
calls with delegated calls to JACOB classes. A simple PERL program
could probably be used to automate this step.
In order to return strongly typed wrappers from method calls, I had to
create a special constructor which constructs the wrapper class instance
and copies over the IDispatch pointer. This is because I can't cast a
java Dispatch object to a super class object.
For example, the Command class has a method like this:
public Connection getActiveConnection();
Ideally, I would like the wrapper code to say:
public Connection getActiveConnection()
{
// this doesn't work
return (Connection)Dispatch.get(this, "ActiveConnection").toDispatch());
}
Thereby wrapping the returned Dispatch pointer in a Connection object.
But, since I can't cast in this way, I use the following construct:
public Connection getActiveConnection()
{
// this works
return new Connection(Dispatch.get(this, "ActiveConnection").toDispatch());
}
Which uses a special constructor inserted into the Connection class:
/**
* This constructor is used instead of a case operation to
* turn a Dispatch object into a wider object - it must exist
* in every wrapper class whose instances may be returned from
* method calls wrapped in VT_DISPATCH Variants.
*/
public Connection(Dispatch d)
{
// take over the IDispatch pointer
m_pDispatch = d.m_pDispatch;
// null out the input's pointer
d.m_pDispatch = 0;
}
I have to add this constructor to any class whose instances I want
to return from wrapped calls.

120
samples/ado/Command.java Normal file
View File

@@ -0,0 +1,120 @@
import com.jacob.com.*;
public class Command extends Dispatch
{
public Command()
{
super("ADODB.Command");
}
/**
* This constructor is used instead of a case operation to
* turn a Dispatch object into a wider object - it must exist
* in every wrapper class whose instances may be returned from
* method calls wrapped in VT_DISPATCH Variants.
*/
public Command(Dispatch d)
{
// take over the IDispatch pointer
m_pDispatch = d.m_pDispatch;
// null out the input's pointer
d.m_pDispatch = 0;
}
public Variant getProperties()
{
return Dispatch.get(this, "Properties");
}
public Connection getActiveConnection()
{
return new Connection(Dispatch.get(this, "ActiveConnection").toDispatch());
}
public void setActiveConnection(Connection ppvObject)
{
Dispatch.put(this, "ActiveConnection", ppvObject);
}
public String getCommandText()
{
return Dispatch.get(this, "CommandText").toString();
}
public void setCommandText(String pbstr)
{
Dispatch.put(this, "CommandText", pbstr);
}
public int getCommandTimeout()
{
return Dispatch.get(this, "CommandTimeout").toInt();
}
public void setCommandTimeout(int plTimeout)
{
Dispatch.put(this, "CommandTimeout", new Variant(plTimeout));
}
public boolean getPrepared()
{
return Dispatch.get(this, "Prepared").toBoolean();
}
public void setPrepared(boolean pfPrepared)
{
Dispatch.put(this, "Prepared", new Variant(pfPrepared));
}
public Recordset Execute(Variant RecordsAffected, Variant Parameters, int Options)
{
return (Recordset)Dispatch.call(this, "Execute", RecordsAffected, Parameters, new Variant(Options)).toDispatch();
}
public Recordset Execute()
{
Variant dummy = new Variant();
return new Recordset(Dispatch.call(this, "Execute", dummy).toDispatch());
}
public Variant CreateParameter(String Name, int Type, int Direction, int Size, Variant Value)
{
return Dispatch.call(this, "CreateParameter", Name, new Variant(Type), new Variant(Direction), new Variant(Size), Value);
}
// need to wrap Parameters
public Variant getParameters()
{
return Dispatch.get(this, "Parameters");
}
public void setCommandType(int plCmdType)
{
Dispatch.put(this, "CommandType", new Variant(plCmdType));
}
public int getCommandType()
{
return Dispatch.get(this, "CommandType").toInt();
}
public String getName()
{
return Dispatch.get(this, "Name").toString();
}
public void setName(String pbstrName)
{
Dispatch.put(this, "Name", pbstrName);
}
public int getState()
{
return Dispatch.get(this, "State").toInt();
}
public void Cancel()
{
Dispatch.call(this, "Cancel");
}
}

View File

@@ -0,0 +1,12 @@
// Enum: CommandTypeEnum
public interface CommandTypeEnum
{
public static final int adCmdUnspecified = -1;
public static final int adCmdUnknown = 8;
public static final int adCmdText = 1;
public static final int adCmdTable = 2;
public static final int adCmdStoredProc = 4;
public static final int adCmdFile = 256;
public static final int adCmdTableDirect = 512;
}

180
samples/ado/Connection.java Normal file
View File

@@ -0,0 +1,180 @@
import com.jacob.com.*;
public class Connection extends Dispatch
{
public Connection()
{
super("ADODB.Connection");
}
/**
* This constructor is used instead of a case operation to
* turn a Dispatch object into a wider object - it must exist
* in every wrapper class whose instances may be returned from
* method calls wrapped in VT_DISPATCH Variants.
*/
public Connection(Dispatch d)
{
// take over the IDispatch pointer
m_pDispatch = d.m_pDispatch;
// null out the input's pointer
d.m_pDispatch = 0;
}
// need to wrap Properties
public Variant getProperties()
{
return Dispatch.get(this, "Properties");
}
public String getConnectionString()
{
return Dispatch.get(this, "ConnectionString").toString();
}
public void setConnectionString(String pbstr)
{
Dispatch.put(this, "ConnectionString", pbstr);
}
public int getCommandTimeout()
{
return Dispatch.get(this, "CommandTimeout").toInt();
}
public void setCommandTimeout(int plTimeout)
{
Dispatch.put(this, "CommandTimeout", new Variant(plTimeout));
}
public int getConnectionTimeout()
{
return Dispatch.get(this, "ConnectionTimeout").toInt();
}
public void setConnectionTimeout(int plTimeout)
{
Dispatch.put(this, "ConnectionTimeout", new Variant(plTimeout));
}
public String getVersion()
{
return Dispatch.get(this, "Version").toString();
}
public void Close()
{
Dispatch.call(this, "Close");
}
// how to deal with RecordsAffected being output?
public Variant Execute(String CommandText, Variant RecordsAffected, int Options)
{
return Dispatch.call(this, CommandText, RecordsAffected, new Variant(Options));
}
public int BeginTrans()
{
return Dispatch.call(this, "BeginTrans").toInt();
}
public void CommitTrans()
{
Dispatch.call(this, "CommitTrans");
}
public void RollbackTrans()
{
Dispatch.call(this, "RollbackTrans");
}
public void Open(String ConnectionString, String UserID, String Password, int Options)
{
Dispatch.call(this, "Open", ConnectionString, UserID, Password, new Variant(Options));
}
public void Open()
{
Dispatch.call(this, "Open");
}
public Variant getErrors()
{
return Dispatch.get(this, "Errors");
}
public String getDefaultDatabase()
{
return Dispatch.get(this, "DefaultDatabase").toString();
}
public void setDefaultDatabase(String pbstr)
{
Dispatch.put(this, "DefaultDatabase", pbstr);
}
public int getIsolationLevel()
{
return Dispatch.get(this, "IsolationLevel").toInt();
}
public void setIsolationLevel(int Level)
{
Dispatch.put(this, "IsolationLevel", new Variant(Level));
}
public int getAttributes()
{
return Dispatch.get(this, "Attributes").toInt();
}
public void setAttributes(int plAttr)
{
Dispatch.put(this, "Attributes", new Variant(plAttr));
}
public int getCursorLocation()
{
return Dispatch.get(this, "CursorLocation").toInt();
}
public void setCursorLocation(int plCursorLoc)
{
Dispatch.put(this, "CursorLocation", new Variant(plCursorLoc));
}
public int getMode()
{
return Dispatch.get(this, "Mode").toInt();
}
public void setMode(int plMode)
{
Dispatch.put(this, "Mode", new Variant(plMode));
}
public String getProvider()
{
return Dispatch.get(this, "Provider").toString();
}
public void setProvider(String pbstr)
{
Dispatch.put(this, "Provider", pbstr);
}
public int getState()
{
return Dispatch.get(this, "State").toInt();
}
public Variant OpenSchema(int Schema, Variant Restrictions, Variant SchemaID)
{
return Dispatch.call(this, "OpenSchema", new Variant(Schema), Restrictions, SchemaID);
}
public void Cancel()
{
Dispatch.call(this, "Cancel");
}
}

124
samples/ado/Field.java Normal file
View File

@@ -0,0 +1,124 @@
import com.jacob.com.*;
public class Field extends Dispatch
{
/**
* This constructor is used instead of a case operation to
* turn a Dispatch object into a wider object - it must exist
* in every wrapper class whose instances may be returned from
* method calls wrapped in VT_DISPATCH Variants.
*/
public Field(Dispatch d)
{
// take over the IDispatch pointer
m_pDispatch = d.m_pDispatch;
// null out the input's pointer
d.m_pDispatch = 0;
}
public Variant getProperties()
{
return Dispatch.get(this, "Properties");
}
public int getActualSize()
{
return Dispatch.get(this, "ActualSize").toInt();
}
public int getAttributes()
{
return Dispatch.get(this, "Attributes").toInt();
}
public int getDefinedSize()
{
return Dispatch.get(this, "DefinedSize").toInt();
}
public String getName()
{
return Dispatch.get(this, "Name").toString();
}
public int getType()
{
return Dispatch.get(this, "Type").toInt();
}
public Variant getValue()
{
return Dispatch.get(this, "Value");
}
public void setValue(Variant pvar)
{
Dispatch.put(this, "Value", pvar);
}
public byte getPrecision()
{
return Dispatch.get(this, "Precision").toByte();
}
public byte getNumericScale()
{
return Dispatch.get(this, "NumericScale").toByte();
}
public void AppendChunk(Variant Data)
{
Dispatch.call(this, "AppendChunk", Data);
}
public Variant GetChunk(int Length)
{
return Dispatch.call(this, "GetChunk", new Variant(Length));
}
public Variant getOriginalValue()
{
return Dispatch.get(this, "OriginalValue");
}
public Variant getUnderlyingValue()
{
return Dispatch.get(this, "UnderlyingValue");
}
public Variant getDataFormat()
{
return Dispatch.get(this, "DataFormat");
}
public void setDataFormat(Variant ppiDF)
{
Dispatch.put(this, "DataFormat", ppiDF);
}
public void setPrecision(byte pb)
{
Dispatch.put(this, "Precision", new Variant(pb));
}
public void setNumericScale(byte pb)
{
Dispatch.put(this, "NumericScale", new Variant(pb));
}
public void setType(int pDataType)
{
Dispatch.put(this, "Type", new Variant(pDataType));
}
public void setDefinedSize(int pl)
{
Dispatch.put(this, "DefinedSize", new Variant(pl));
}
public void setAttributes(int pl)
{
Dispatch.put(this, "Attributes", new Variant(pl));
}
}

50
samples/ado/Fields.java Normal file
View File

@@ -0,0 +1,50 @@
import com.jacob.com.*;
public class Fields extends Dispatch
{
/**
* This constructor is used instead of a case operation to
* turn a Dispatch object into a wider object - it must exist
* in every wrapper class whose instances may be returned from
* method calls wrapped in VT_DISPATCH Variants.
*/
public Fields(Dispatch d)
{
// take over the IDispatch pointer
m_pDispatch = d.m_pDispatch;
// null out the input's pointer
d.m_pDispatch = 0;
}
public int getCount()
{
return Dispatch.get(this, "Count").toInt();
}
public Variant _NewEnum()
{
return Dispatch.call(this, "_NewEnum");
}
public void Refresh()
{
Dispatch.call(this, "Refresh");
}
public Field getItem(int Index)
{
return new Field(Dispatch.call(this, "Item", new Variant(Index)).toDispatch());
}
public void Append(String Name, int Type, int DefinedSize, int Attrib)
{
Dispatch.call(this, "Append", Name, new Variant(Type),
new Variant(DefinedSize), new Variant(Attrib));
}
public void Delete(Variant Index)
{
Dispatch.call(this, "Delete", Index);
}
}

411
samples/ado/Recordset.java Normal file
View File

@@ -0,0 +1,411 @@
import com.jacob.com.*;
public class Recordset extends Dispatch
{
public Recordset()
{
super("ADODB.Recordset");
}
/**
* This constructor is used instead of a case operation to
* turn a Dispatch object into a wider object - it must exist
* in every wrapper class whose instances may be returned from
* method calls wrapped in VT_DISPATCH Variants.
*/
public Recordset(Dispatch d)
{
// take over the IDispatch pointer
m_pDispatch = d.m_pDispatch;
// null out the input's pointer
d.m_pDispatch = 0;
}
public Variant getProperties()
{
return Dispatch.get(this, "Properties");
}
public int getAbsolutePosition()
{
return Dispatch.get(this, "AbsolutePosition").toInt();
}
public void setAbsolutePosition(int pl)
{
Dispatch.put(this, "AbsolutePosition", new Variant(pl));
}
public Connection getActiveConnection()
{
return new Connection(Dispatch.get(this, "ActiveConnection").toDispatch());
}
public void setActiveConnection(Connection ppvObject)
{
Dispatch.put(this, "ActiveConnection", ppvObject);
}
public void setActiveConnection(Variant ppvObject)
{
Dispatch.put(this, "ActiveConnection", ppvObject);
}
public boolean getBOF()
{
return Dispatch.get(this, "BOF").toBoolean();
}
public Variant getBookmark()
{
return Dispatch.get(this, "Bookmark");
}
public void setBookmark(Variant pvBookmark)
{
Dispatch.put(this, "Bookmark", pvBookmark);
}
public int getCacheSize()
{
return Dispatch.get(this, "CacheSize").toInt();
}
public void setCacheSize(int pl)
{
Dispatch.put(this, "CacheSize", new Variant(pl));
}
public int getCursorType()
{
return Dispatch.get(this, "CursorType").toInt();
}
public void setCursorType(int pl)
{
Dispatch.put(this, "CursorType", new Variant(pl));
}
public boolean getEOF()
{
return Dispatch.get(this, "EOF").toBoolean();
}
public Fields getFields()
{
return new Fields(Dispatch.get(this, "Fields").toDispatch());
}
public int getLockType()
{
return Dispatch.get(this, "LockType").toInt();
}
public void setLockType(int plLockType)
{
Dispatch.put(this, "LockType", new Variant(plLockType));
}
public int getMaxRecords()
{
return Dispatch.get(this, "MaxRecords").toInt();
}
public void setMaxRecords(int pl)
{
Dispatch.put(this, "MaxRecords", new Variant(pl));
}
public int getRecordCount()
{
return Dispatch.get(this, "RecordCount").toInt();
}
public void setSource(Object pvSource)
{
Dispatch.put(this, "Source", pvSource);
}
public void setSource(String pvSource)
{
Dispatch.put(this, "Source", pvSource);
}
public Variant getSource()
{
return Dispatch.get(this, "Source");
}
public void AddNew(Variant FieldList, Variant Values)
{
Dispatch.call(this, "AddNew", FieldList, Values);
}
public void CancelUpdate()
{
Dispatch.call(this, "CancelUpdate");
}
public void Close()
{
Dispatch.call(this, "Close");
}
public void Delete(int AffectRecords)
{
Dispatch.call(this, "Delete", new Variant(AffectRecords));
}
public Variant GetRows(int Rows, Variant Start, Variant Fields)
{
return Dispatch.call(this, "GetRows", new Variant(Rows), Start, Fields);
}
// get all rows
public Variant GetRows()
{
return Dispatch.call(this, "GetRows");
}
public void Move(int NumRecords, Variant Start)
{
Dispatch.call(this, "Move", new Variant(NumRecords), Start);
}
public void MoveNext()
{
Dispatch.call(this, "MoveNext");
}
public void MovePrevious()
{
Dispatch.call(this, "MovePrevious");
}
public void MoveFirst()
{
Dispatch.call(this, "MoveFirst");
}
public void MoveLast()
{
Dispatch.call(this, "MoveLast");
}
public void Open(Variant Source, Variant ActiveConnection, int CursorType, int LockType, int Options)
{
Dispatch.call(this, "Open", Source, ActiveConnection, new Variant(CursorType), new Variant(LockType), new Variant(Options));
}
public void Open(Variant Source, Variant ActiveConnection)
{
Dispatch.call(this, "Open", Source, ActiveConnection);
}
public void Requery(int Options)
{
Dispatch.call(this, "Requery", new Variant(Options));
}
public void Update(Variant Fields, Variant Values)
{
Dispatch.call(this, "Update", Fields, Values);
}
public int getAbsolutePage()
{
return Dispatch.get(this, "AbsolutePage").toInt();
}
public void setAbsolutePage(int pl)
{
Dispatch.put(this, "AbsolutePage", new Variant(pl));
}
public int getEditMode()
{
return Dispatch.get(this, "EditMode").toInt();
}
public Variant getFilter()
{
return Dispatch.get(this, "Filter");
}
public void setFilter(Variant Criteria)
{
Dispatch.put(this, "Filter", Criteria);
}
public int getPageCount()
{
return Dispatch.get(this, "PageCount").toInt();
}
public int getPageSize()
{
return Dispatch.get(this, "PageSize").toInt();
}
public void setPageSize(int pl)
{
Dispatch.put(this, "PageSize", new Variant(pl));
}
public String getSort()
{
return Dispatch.get(this, "Sort").toString();
}
public void setSort(String Criteria)
{
Dispatch.put(this, "Sort", Criteria);
}
public int getStatus()
{
return Dispatch.get(this, "Status").toInt();
}
public int getState()
{
return Dispatch.get(this, "State").toInt();
}
public void UpdateBatch(int AffectRecords)
{
Dispatch.call(this, "UpdateBatch", new Variant(AffectRecords));
}
public void CancelBatch(int AffectRecords)
{
Dispatch.call(this, "CancelBatch", new Variant(AffectRecords));
}
public int getCursorLocation()
{
return Dispatch.get(this, "CursorLocation").toInt();
}
public void setCursorLocation(int pl)
{
Dispatch.put(this, "CursorLocation", new Variant(pl));
}
public Recordset NextRecordset(Variant RecordsAffected)
{
return new Recordset(Dispatch.call(this, "NextRecordset", RecordsAffected).toDispatch());
}
public boolean Supports(int CursorOptions)
{
return Dispatch.call(this, "Supports", new Variant(CursorOptions)).toBoolean();
}
public Variant getCollect(Variant Index)
{
return Dispatch.get(this, "Collect");
}
public void setCollect(Variant Index, Variant pvar)
{
Dispatch.call(this, "Collect", Index, pvar);
}
public int getMarshalOptions()
{
return Dispatch.get(this, "MarshalOptions").toInt();
}
public void setMarshalOptions(int pl)
{
Dispatch.put(this, "MarshalOptions", new Variant(pl));
}
public void Find(String Criteria, int SkipRecords, int SearchDirection, Variant Start)
{
Dispatch.call(this, "Find", Criteria, new Variant(SkipRecords), new Variant(SearchDirection), Start);
}
public void Cancel()
{
Dispatch.call(this, "Cancel");
}
public Variant getDataSource()
{
return Dispatch.get(this, "DataSource");
}
public void setDataSource(Variant ppunkDataSource)
{
Dispatch.put(this, "DataSource", ppunkDataSource);
}
public void Save(String FileName, int PersistFormat)
{
Dispatch.call(this, "Save", FileName, new Variant(PersistFormat));
}
public Variant getActiveCommand()
{
return Dispatch.get(this, "ActiveCommand");
}
public void setStayInSync(boolean pb)
{
Dispatch.put(this, "StayInSync", new Variant(pb));
}
public boolean getStayInSync()
{
return Dispatch.get(this, "StayInSync").toBoolean();
}
public String GetString(int StringFormat, int NumRows, String ColumnDelimeter, String RowDelimeter, String NullExpr)
{
return Dispatch.call(this, "GetString", new Variant(StringFormat),
new Variant(NumRows), ColumnDelimeter, RowDelimeter, NullExpr).toString();
}
public String getDataMember()
{
return Dispatch.get(this, "DataMember").toString();
}
public void setDataMember(String pl)
{
Dispatch.put(this, "DataMember", new Variant(pl));
}
public int CompareBookmarks(Variant Bookmark1, Variant Bookmark2)
{
return Dispatch.call(this, "CompareBookmarks", Bookmark1, Bookmark2).toInt();
}
public Recordset Clone(int LockType)
{
return new Recordset(Dispatch.call(this, "Clone",
new Variant(LockType)).toDispatch());
}
public void Resync(int AffectRecords, int ResyncValues)
{
Dispatch.call(this, "Resync", new Variant(AffectRecords), new Variant(ResyncValues));
}
public void Seek(Variant KeyValues, int SeekOption)
{
Dispatch.call(this, "Seek", KeyValues, new Variant(SeekOption));
}
public void setIndex(String pl)
{
Dispatch.put(this, "Index", new Variant(pl));
}
public String getIndex()
{
return Dispatch.get(this, "Index)").toString();
}
}

3
samples/ado/ms/README Normal file
View File

@@ -0,0 +1,3 @@
This is the WFC equivalent of the JACOB ADO example.
This code must be compiled with JVC and run with JVIEW.

View File

@@ -0,0 +1,64 @@
import com.ms.com.*;
import com.ms.wfc.data.*;
// an ms-only version of test.java
public class testms
{
public static void printRS(Recordset rs)
{
Fields fs = rs.getFields();
for (int i=0;i<fs.getCount();i++)
{
System.out.print(fs.getItem(i).getName() + " ");
}
System.out.println("");
rs.moveFirst();
while (!rs.getEOF())
{
for(int i=0;i<fs.getCount();i++)
{
Field f = fs.getItem(i);
Variant v = f.getValue();
System.out.print(v + " ");
}
System.out.println("");
rs.moveNext();
}
}
// open a recordset directly
public static void getRS(String con, String query)
{
System.out.println("Recordset Open");
Recordset rs = new Recordset();
rs.open(new Variant(query), new Variant(con));
printRS(rs);
}
// create connection and command objects and use them
// to get a recordset
public static void getCommand(String con, String query)
{
System.out.println("Command+Connection -> Recordset");
Connection c = new Connection();
c.setConnectionString(con);
c.open();
Command comm = new Command();
comm.setActiveConnection(c);
comm.setCommandType(AdoEnums.CommandType.TEXT);
comm.setCommandText(query);
Recordset rs = comm.execute();
printRS(rs);
c.close();
}
public static void main(String[] args)
{
String connectStr = "DRIVER=SQL Server;SERVER=DANADLER;UID=sa;PWD=;WSID=DANADLER;DATABASE=pubs";
String queryStr = "select * from authors";
getCommand(connectStr, queryStr);
getRS(connectStr, queryStr);
}
}

62
samples/ado/test.java Normal file
View File

@@ -0,0 +1,62 @@
import com.jacob.com.*;
public class test
{
public static void printRS(Recordset rs)
{
Fields fs = rs.getFields();
for (int i=0;i<fs.getCount();i++)
{
System.out.print(fs.getItem(i).getName() + " ");
}
System.out.println("");
rs.MoveFirst();
while (!rs.getEOF())
{
for(int i=0;i<fs.getCount();i++)
{
Field f = fs.getItem(i);
Variant v = f.getValue();
System.out.print(v + " ");
}
System.out.println("");
rs.MoveNext();
}
}
// open a recordset directly
public static void getRS(String con, String query)
{
System.out.println("Recordset Open");
Recordset rs = new Recordset();
rs.Open(new Variant(query), new Variant(con));
printRS(rs);
}
// create connection and command objects and use them
// to get a recordset
public static void getCommand(String con, String query)
{
System.out.println("Command+Connection -> Recordset");
Connection c = new Connection();
c.setConnectionString(con);
c.Open();
Command comm = new Command();
comm.setActiveConnection(c);
comm.setCommandType(CommandTypeEnum.adCmdText);
comm.setCommandText(query);
Recordset rs = comm.Execute();
printRS(rs);
c.Close();
}
public static void main(String[] args)
{
String connectStr = "DRIVER=SQL Server;SERVER=DANADLER;UID=sa;PWD=;WSID=DANADLER;DATABASE=pubs";
String queryStr = "select * from authors";
getCommand(connectStr, queryStr);
getRS(connectStr, queryStr);
}
}