Check if database table is empty

I’m trying to check if database table is empty, for example I insert there some data and then after 1-3 min it is taken from DB. In this time I want to check if that data is already taken. How could I perform such action ?

I had an idea to make a while statement where it will select that data size and if selected data size will be null, so it will make another action.

This is what I have tried:

while(updateResult.getSelectResults("SELECT * FROM pushing2.CustomerEvents WHERE Action = 1").size() == 0) {
}

It is always dangerous to use while loop without any emergency brake. I’d rather use for loop with maximum number of loop execution.

This is what I’d do:

boolean isEmpty = false

for(int i = 0; i < 180; i++) {
	isEmpty = updateResult.getSelectResults("SELECT * FROM pushing2.CustomerEvents WHERE Action = 1").size() == 0
	
	if(isEmpty) {
		KeywordUtil.logInfo("The table is empty now.")
		break
	}
	
	WebUI.delay(1)
}

if(!isEmpty) {
	KeywordUtil.markFailed("The table is not empty after defined timeout.")
}
2 Likes

Sorry for the late answer. This is what I wanted to make, thanks !