Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
DougIrwin
Contributor
Contributor

Reusing tDBConnection over mutliple Hosts dynamically.

Hi all,

New to Talend but I've been around a long time with data and coding.

I need to pull data from a bunch of servers that have a consistent database and table name structure. I've set up a basic tDBConnection->tDBInput->tLogRow->tDBClose prototype that works fine.

Then I've added a tJava at the very beginning to try to get the Connection as an object, with a view to updating the Host in the Connection dynamically. The aim is to change this to some kind of Iterator, once I've proven this can work.

Unfortunately I'm not having any luck getting the Connection in the tJava, which throws this at runtime:

Starting job ConnectionTest at 14:38 28/08/2025.
[statistics] connecting to socket on port 3689
[statistics] connected
Exception in component tJava_1 (ConnectionTest)
java.lang.NullPointerException: Cannot invoke "java.sql.Connection.getMetaData()" because "c" is null
at xxx.connectiontest_0_1.ConnectionTest.tJava_1Process(ConnectionTest.java:552)
at xxx.connectiontest_0_1.ConnectionTest.runJobInTOS(ConnectionTest.java:2397)
at xxx.connectiontest_0_1.ConnectionTest.main(ConnectionTest.java:2035)
[FATAL] 14:38:56 xxx.connectiontest_0_1.ConnectionTest- tJava_1 Cannot invoke "java.sql.Connection.getMetaData()" because "c" is null
java.lang.NullPointerException: Cannot invoke "java.sql.Connection.getMetaData()" because "c" is null
at xxx.connectiontest_0_1.ConnectionTest.tJava_1Process(ConnectionTest.java:552) [classes/:?]
at xxx.connectiontest_0_1.ConnectionTest.runJobInTOS(ConnectionTest.java:2397) [classes/:?]
at xxx.connectiontest_0_1.ConnectionTest.main(ConnectionTest.java:2035) [classes/:?]
[statistics] disconnected

Job ConnectionTest ended at 14:38 28/08/2025. [Exit code = 1]

See attachment for what I have, which is working so long as the tJava is disabled.

Any suggestions would be gratefully received.

Labels (2)
1 Solution

Accepted Solutions
Dave_Simo
Creator II
Creator II

Hello @DougIrwin 

Yes in tFixedFlowInput_2 I linked it with row1.values.

Dave_Simo_0-1756711023301.png

And as input I have this in tFixedFlowInput_1

Dave_Simo_1-1756711089933.png

Best Regards

 

View solution in original post

8 Replies
Denis_Segard
Support
Support

Hello,

You may define the Host as a context variable and set this context variable in a tJava or any other way ..

Denis_Segard_0-1756360185078.png

Kind regards
Denis

DougIrwin
Contributor
Contributor
Author

Hey Denis!

So I got the email about your reply and created a context.hostName, setting it to an initial value and updating my tDBConneciton object to use that. Running that worked, so I modified the tJava to change context.hostName to a different server. That worked perfectly!

Thanks so much for the tip! Now to get an iterator and list and etc, etc 🙂

Thanks again!

DougIrwin
Contributor
Contributor
Author

One thing I just noticed with this solution is that it doesn't work well with parallel execution - I assume because context variables are global. Does anyone know if there's a way to do this that would work with parallel execution?

Dave_Simo
Creator II
Creator II

Hello @DougIrwin 


I don't know how you set up your parallelism, but try this design maybe it will help you.

Dave_Simo_0-1756471486832.png

With 2 parallel executions for example.

Dave_Simo_1-1756471579346.png

 

Best Regards

DougIrwin
Contributor
Contributor
Author

I seem to be missing something. How is your tFixedFlowInput_2 picking up the data from tFlowToIterate_1 to display in the tLogRow ??

DougIrwin
Contributor
Contributor
Author

Ah looks like you "bind" the row1.values in tFixedFlowInput_2. At least that works for me. Not sure if I can then use this in a tDBConnection but I'll have a play with it. Thanks for the suggestion!

Dave_Simo
Creator II
Creator II

Hello @DougIrwin 

Yes in tFixedFlowInput_2 I linked it with row1.values.

Dave_Simo_0-1756711023301.png

And as input I have this in tFixedFlowInput_1

Dave_Simo_1-1756711089933.png

Best Regards

 

DougIrwin
Contributor
Contributor
Author

Thanks @Dave_Simo that's essentially the same as what I have - the only difference being my column names. Works a charm, thanks!