Skip to main content
Announcements
Accelerate Your Success: Fuel your data and AI journey with the right services, delivered by our experts. Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Retry DB connection

Hello !

 

how can I retry a database connection once the first time it failure ? I mean, is there a kind of loop to keep trying connecting the database until a success connection?

 

Best Regards!!

Labels (3)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Hello, I could solve the problem:

this is the correct code:

try{  

if ( ((Integer)globalMap.get("tLoop_1_CURRENT_ITERATION"))!=null&&((Integer)globalMap.get("tLoop_1_CURRENT_ITERATION")) > 1)
{	
	Thread.sleep(10000);
}

}catch(Exception e){
	if (((Integer)globalMap.get("tLoop_1_CURRENT_ITERATION"))!=null&&((Integer)globalMap.get("tLoop_1_CURRENT_ITERATION")) > 50)
	{
		context.continueLooping = false;
	}
	else
	{
		System.out.println("Tentativa n°: "+((Integer)globalMap.get("tLoop_1_CURRENT_ITERATION")));
	}
}

 

View solution in original post

3 Replies
desanip
Contributor
Contributor

You can establish a loop to determine if the connection to database is successful. You will find more info in the below link.

 

https://www.barmartland.com/retry-failed-connections-in-talend/

Anonymous
Not applicable
Author

hello,

tks!

I don't know What I am doing wrong I have followed all instruction but I got this errors

Starting job Customers at 12:16 03/05/2019.
[statistics] connecting to socket on port 3822
[statistics] connected
Exception in component tJavaFlex_2 (Customers)
java.lang.NullPointerException
	at local_project.customers_1_0.Customers.tLoop_1Process(Customers.java:790)
	at local_project.customers_1_0.Customers.tJava_1Process(Customers.java:482)
	at local_project.customers_1_0.Customers.runJobInTOS(Customers.java:1220)
	at local_project.customers_1_0.Customers.main(Customers.java:1054)
[statistics] disconnected

Job Customers ended at 12:16 03/05/2019. [exit code=1]

I am using this code:

// start part of your Java code
try{  
// here is the main part of the component,
// a piece of code executed in the row
// loop
if (((Integer)globalMap.get("tLoop_1_CURRENT_INTERATION")) > 1)
{	
	Thread.sleep(1500);
}
// end of the component, outside/closing the loop
}catch(Exception e){
	if (((Integer)globalMap.get("tLoop_1_CURRENT_INTERATION")) > 5)
	{
		context.continueLooping = false;
	}
	else
	{
		System.out.println("Connection failed. Retrying..");
	}
}

Java error talend.PNG

Anonymous
Not applicable
Author

Hello, I could solve the problem:

this is the correct code:

try{  

if ( ((Integer)globalMap.get("tLoop_1_CURRENT_ITERATION"))!=null&&((Integer)globalMap.get("tLoop_1_CURRENT_ITERATION")) > 1)
{	
	Thread.sleep(10000);
}

}catch(Exception e){
	if (((Integer)globalMap.get("tLoop_1_CURRENT_ITERATION"))!=null&&((Integer)globalMap.get("tLoop_1_CURRENT_ITERATION")) > 50)
	{
		context.continueLooping = false;
	}
	else
	{
		System.out.println("Tentativa n°: "+((Integer)globalMap.get("tLoop_1_CURRENT_ITERATION")));
	}
}