How to use java var on SQL query ?

Highlighted
Seven Stars

How to use java var on SQL query ?

Hello,  I have on my tXMLMap,some values , and with this values, I would like to make a sql query to get the id on the table and insert this id to an another SQL query .

First, I used tSetGlobalVar, but in my sql query ( Oracle Row) it doing nothing.

My query is like

"SELECT max(my_table_name) as table_id FROM table WHERE  table.name =' " + id  + "' 

ID was the name of my SetGlobalVar , I use

StringHandling.UPCASE(row2.USERNAME) 

for the Value

 

 

How can I use the query and insert into the tOracleOutput ? tos.PNG


Accepted Solutions
Fifteen Stars TRF
Fifteen Stars

Re: How to use java var on SQL query ?

You can connect your tOracle(or other DB)Input component to a tSetGlobalVar to get the result into a new global variable.

Then, or you use a tOracleRow and you introduce the query by yourself (using the preceding global variable).

You map also use a standard tOracleOutput component for which the desired field will be populated with the global variable content (probably in a tMap or tJavaRow).

 

Thank's to mark your case as solved and open a new one for new or derived questions.


TRF

All Replies
Fifteen Stars TRF
Fifteen Stars

Re: How to use java var on SQL query ?

Hi,

If you have a global variable called "id" you have to change your query like this one:

"SELECT max(my_table_name) as table_id FROM table WHERE  table.name = '" + (String)globalMap.get("id")  + "'"

Hope this helps.

 


TRF
Seven Stars

Re: How to use java var on SQL query ?

Hello, and thanks for the solution, its working, but now, I want to get this result of my query and add to the other query  Its be like

Insert into my_table (table1,table2table3) 
Values("Her the result of my first query","test",1)
Fifteen Stars TRF
Fifteen Stars

Re: How to use java var on SQL query ?

You can connect your tOracle(or other DB)Input component to a tSetGlobalVar to get the result into a new global variable.

Then, or you use a tOracleRow and you introduce the query by yourself (using the preceding global variable).

You map also use a standard tOracleOutput component for which the desired field will be populated with the global variable content (probably in a tMap or tJavaRow).

 

Thank's to mark your case as solved and open a new one for new or derived questions.


TRF

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Why Companies Move to the Cloud: 7 Success Stories

Learn how and why companies are moving to the Cloud

Read Now