+ Start a Discussion
PanchoPancho 

WHERE [something] IN : (something) not working in JAVA

Hi,

I am moving this APEX code over to a JAVA app, and my query is not working.  

Any help is greatly appreciated.

Any ideas?

 

APEX Code:

List<String> zips = new List<String>();

//loaded up the list then I execute this query 

List<Zip_Code_Master__c> zipList= [select name, id, Related_Metro_Area__r.id from Zip_Code_Master__c where name =:zips];

 

 

JAVA Code:

String[] zips = new String[MaxRows];

//loaded up the list then I execute this query

QueryResult queryResults = connection.query("select name, id, Related_Metro_Area__r.id from Zip_Code_Master__c where name IN : zips");

 

JAVA Error:

[MalformedQueryFault [ApiQueryFault [ApiFault exceptionCode='MALFORMED_QUERY'
exceptionMessage='
Zip_Code_Master__c where name IN : zips
^
ERROR at Row:1:Column:80
unexpected token: ':' (Bind variables only allowed in Apex code)'
]
row='1'
column='80'
]

sfdcfoxsfdcfox
The binding syntax (:variable) only works in Apex Code. In Java, you have to format your own SOQL query by using StringUtils.join or Arrays.toString().