cancel
Showing results for 
Search instead for 
Did you mean: 

java connector example code

Former Member
0 Kudos

are there any java connector code samples which demonstrate on how to do simple queries as searching a customer and displaying the customer's address details? or modify an existing customer entry and such?

kind regards

pascal

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello Pascal,

The following code shows you how to use the Recordset and how to load up a BusinessPartners object. It gives you an overview of how to use the objects. Have a look at it and any questions get back to me.

Talk later,

Cormac

public void browseBPs(){

IRecordset rs=null;

IBusinessPartners bp=null;

try{

rs=SBOCOMUtil.newRecordset(vCompany);

rs.doQuery("SELECT * FROM OCRD");

rs.moveFirst();

int i=0;

while (!rs.isEoF().booleanValue() && i<10){

String cardCode=null;

cardCode=(String)rs.getFields().item("CARDCODE").getValue();

//System.out.println("Opening: " + cardCode);

bp=SBOCOMUtil.newBusinessPartners(vCompany);

if (bp.getByKey(cardCode)== true){

System.out.println("*******************************");

System.out.println("BP Name:\t" + bp.getCardName());

System.out.println("BP Address:\t" + bp.getAddress());

System.out.println("*******************************");

}

rs.moveNext();

i++;

}

}catch(Exception e){

e.printStackTrace();

}

}

Former Member
0 Kudos

thanks, this was really helpful!

now i need to get the right vCompany. according to the api-docs that's an instance of ICompany and it seems like this is the way to set all the connection parameters... how do i do that?

maybe i should be more precise.. what exact properties of the ICompany do i have to set in order to connect to a company?

i tried with the folowing but did not succeed:

vCompany = SBOCOMUtil.newCompany();

vCompany.setServer("10.0.0.152"); //the sap / sql server's ip address

vCompany.setCompanyDB("SBODemo_Swiss");

vCompany.setUserName("username");

vCompany.setPassword("password");

vCompany.connect(); //returns -8008 (Error while trying to initialize database)

(of course i replaced username and password with those of a valid user)

if i add those two lines before the connect statement:

vCompany.setDbUserName("sa");

vCompany.setDbPassword("password");

connect returns -111 which means "Connection to SBO-Common has failed"

adding a line that sets the language doesn't change anything..

now i don't know if this really was a step forward or not, but i think it was since i get -8008 even if i enter the wrong ip ...

what am i missing?

if all these questions have already been answered in a tutorial or in any document, please give me a link or a hint what to look for, since i didn't find it so far.

kind regards

pascal suter

<i>i keep updating this post as i proceed and as long as i don't get an answer ;)</i>

Message was edited by: Pascal Suter

Former Member
0 Kudos

Hi Pascal,

Have a look through the forum, lots of posts on the -111 issue, have a look one of them might give you an idea.

-Cormac

Former Member
0 Kudos

thanks for the hint

i have just solved the problem more or less... i actually didn't change anything on my code but i re-installed the whole sap business one installation on my destkop. the problem is. i am totally new to sap business one and i have just recently gotten my full version cd's, so they are probably a rather new version. for whatever reason though, the sdk installation doesn't install the java connector with it, allthough i select it to be installed in the custom setup. that's why i've installed the java connector from my (elder, but still 2004) evaluation cd.

obviousley there was a version conflict which caused that error.. so now after i've installed it all new and even installed the new sdk and the elder java connector together the whole logon works. (as i stated, without changing a line of code). now the next problem i have is, that i get a COM exception , when i try to rs.doQuery() as described in your example... so i guess that's just another compatiblity issue.. so i now have to wait for an answer from sap concerning my obviousley incomplete sdk in the fullversion.

thanks again for your help, your good example really helped me to understand the java connector and i hope sap will be able to solve the rest of my problem soon.

cheers

pascal

Answers (0)