Skip to content

Instantly share code, notes, and snippets.

@serialhex
Created July 15, 2013 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save serialhex/6001896 to your computer and use it in GitHub Desktop.
Save serialhex/6001896 to your computer and use it in GitHub Desktop.
import com.jacob.com.*;
public class Foo {
public static void main(String[] args) {
System.out.println("Hello world!");
// QBFC constants looked up using the object browser
Variant ctLocalQDB = new Variant(1);
Variant omDontCare = new Variant(2);
// major and minor version of qbXML used to talk to QuickBooks
Variant qbXMLMajor = new Variant(6);
Variant qbXMLMinor = new Variant(0);
// location of the company file to access
String qbFile = "C:\\Documents and Settings\\rdavis\\Desktop\\FfAMETest.QBW";
// connect to QuickBooks
Dispatch qbsm = new Dispatch("QBFC7.QBSessionManager");
Dispatch.call(qbsm, "OpenConnection2", "", "My Sample App", ctLocalQDB);
Dispatch.call(qbsm, "BeginSession", qbFile, omDontCare);
// build and execute a request to obtain all vendors
Dispatch msgSet = Dispatch.call(qbsm, "CreateMsgSetRequest", "US", qbXMLMajor, qbXMLMinor).toDispatch();
Dispatch.call(msgSet, "AppendVendorQueryRq");
Dispatch resSet = Dispatch.call(qbsm, "DoRequests", msgSet).toDispatch();
Dispatch resList = Dispatch.get(resSet, "ResponseList").toDispatch();
int count = Dispatch.get(resList, "Count").getInt();
for (int i = 0; i < count; i++) {
Dispatch res = Dispatch.call(resList, "GetAt", new Variant(i)).toDispatch();
// blindly assume that we have a vendor response
Dispatch vendList = Dispatch.get(res, "Detail").toDispatch();
int vcount = Dispatch.get(vendList, "Count").getInt();
for (int j = 0; j < vcount; j++) {
Dispatch vend = Dispatch.call(vendList, "GetAt", new Variant(j)).toDispatch();
Dispatch dname = Dispatch.get(vend, "Name").toDispatch();
String name = Dispatch.call(dname, "GetValue").getString();
System.out.println("Vendor: " + name);
}
}
// close the QuickBooks connection
Dispatch.call(qbsm, "EndSession");
Dispatch.call(qbsm, "CloseConnection");
System.out.println("Goodbye world!");
}
}
@ashwin-raj
Copy link

got error com.jacob.com.ComFailException: Can't co-create object

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment