One Star

SQL Query with parameters

Hi,
I create SQL query with parameters :
"select COUNT(*) from APPLICATIONFRC where APPLICATIONNAME = ? and APPLICATIONVERSION = ?"
How to pass parameters in tJavaDBInput with this query ?
tJavaDBInput do not accept row line, only iterate.

cdt,
Arnaud
5 REPLIES
Community Manager

Re: SQL Query with parameters

Hello
tFileInputDelimited--row1--tFlowToIterated--iterate--tJavaDBInput---tLogRow
on tJavaDBInput, type in the sql as:
"select COUNT(*) from APPLICATIONFRC where APPLICATIONNAME ="+(String)globalMap.get("row1.columnName1")+" and APPLICATIONVERSION ="+(String)globalMap.get("row1.columnName2")
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: SQL Query with parameters

I know this solution but you cant use it with query defined in "DB connections>Queries" because query is generic and you dont know the name of flow.
Community Manager

Re: SQL Query with parameters

Hello
"DB connections>Queries" because query is generic and you dont know the name of flow.

If you use the query from repository, you can change the query type from repository to built-in and edit the query.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: SQL Query with parameters

Then there are no component to use Queries in repository with parameters like tMap ? its maybe a suggest, a new component for the futur
Six Stars

Re: SQL Query with parameters

Yeah, I agree, parametrizable queries would be a very welcomed and good feature in Talend, instead of going old-school with java string concatenation and escaping...
ie. a feature to accept queries that can use context or talend var seamlessly would be very good and provide clean syntax, ie.

"select field1, field2 from mytable where field1 = {context.var1} and field2 = {context.var2}"

I think would be easy to implement Talend side given the possibility to use very well known templating opensource engine like Freemarker.