To access salesforce data from java we follow the following steps
1)You need to generate wsdl file from your salesforce organization.To do that
2)Go to ->Setup->Develop->Api->Generate Enterprise WSDL
Then one “WSDL” file generated with the extension either “.wsdl,.xml”
3)Now you need to download wsc-20.jar file from the site
Now follow create a jar file for your “Enterprise WSDL” using this WSC-20.jar from command prompt
4)Before do this you need to check java is installed on your system or not.If java is installed then proceed further.
To create jar you follow the follow the following method as show.
5)At command prompt you type like below/
java -classpath D:\balujava\wsc-20.jar com.sforce.ws.tools.wsdlc D:\balujava\Enterprise.xml D:\balujava\Enterprise.jar
If you’re facing Version conflict then u need to change the command like
Java -DcompileTarget=1.7 -classpath D:\balujava\wsc-20.jar com.sforce.ws.tools.wsdlc D:\balujava\Enterprise.xml D:\balujava\Enterprise.jar
Here” D:\balujava” is the location where our files “wsc-20.jar and Enterprise.xml” stored and Enterprise.jar is a jar file we want to create for Enterprise.xml(wsdl file) using wsc-20.jar.See the below screenshot.
7)Now the Jar file is created for our “Enter Prise Wsdl” as shown below
10)Then click on “Next” button
11)Now Click on “Libraries” tab .Then one window opened as shown below.
12)Now click on “Add External Jar’s” button then one window opened as shown below and then select wsc-20.jar and Enterprise.jar files as shown below
13)After adding these two files the newproject look like as shown below.
14)Now Click on Finish button.
Now go to “Test Java Project1” and click on that and then click on “ReferencedLibraries” to check whether the “two jar files are added or not”.
15)We can add these Jar files after saving Project also.
Now we are going through that also.
First “Right click on Project Name You have created”
Click on Properties as shown below.
17)Now “Click on Add External JARs”button and add “WSC-20.jar ,Enterprise.jar” files to Project as explain above images after this image.
Now paste the following code and run it “Runas”java application.
Once you have imported your WSDL file, you can begin building client applications that use the API. Use the following samples to create a basic client application. Comments embedded in the sample explain each section of code.
This section walks through a sample Java client application that uses the WSC SOAP client. The purpose of this sample application is to show the required steps for logging into the login server and to demonstrate the invocation and subsequent handling of several API calls. This sample application performs the following main tasks:
2. Calls login() to log in to the single login server and, if the login succeeds:
o Turns on trace logs so that SOAP messages are printed to a file on the client host.
o Retrieves user information and prints it to the console.
3. Calls describeGlobal() to retrieve a list of all available objects for the organization’s data.
4. Calls describeSObject() to retrieve metadata (field list and object properties) for a specified object.
5. Calls query(), passing a simple query string ( "SELECT FirstName, LastName FROM Contact"), and iterating through the returned QueryResult.
Note the error handling code that follows each API call.