Created
July 15, 2013 17:45
-
-
Save serialhex/6001896 to your computer and use it in GitHub Desktop.
qb-test.java, from
http://www.molecularbear.com/blog/?p=60
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
got error com.jacob.com.ComFailException: Can't co-create object