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

Cloud Free Trial

Try Talend Cloud free for 30 days.

Tutorial

Introduction to Talend Open Studio for Data Integration.

Definitive Guide to Data Integration

Practical steps to developing your data integration strategy.

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.