0

I have a method which runs a JDBC call into a database to gather expected results which I then assert against with results gathered from UI using another method using Selenium.

The problem I'm facing here is that it's possible for the query to not get any results so when I call the method which would send back a string, it actually sends back NULL when the query result is empty.

This causes problems when I try to assert against the UI values. Selenium will return an empty string for the value in question while the db returns NULL.

So to get my assertEquals to match I ideally want the db method to return "" instead of NULL.

I've tried a .replace and an IF statement but it always returns NULL.

The code from my JDBC method looks like this in case this helps:

String strMedicare = rs.getString("_Provider_Number");
return strMedicare;
Keale
  • 3,924
  • 3
  • 29
  • 46
Matt
  • 501
  • 1
  • 12
  • 26
  • 1
    see https://stackoverflow.com/questions/192078/how-do-i-get-the-size-of-a-java-sql-resultset – Scary Wombat Jun 26 '18 at 02:24
  • 1
    `String strMedicare = "" + rs.getString("_Provider_Number");` – Bill Hileman Jun 26 '18 at 14:55
  • Thanks for all the replies. I ended up taking the approach as linked by @ScaryWombat where I do a row count first and then pass my code through an if statement that returns "" is rowcount = 0. Feels like a long winded approach but it works. – Matt Jun 27 '18 at 05:51
  • Just saw the comment by @BillHileman which seems a much quickest solution to the one I implemented. – Matt Jun 27 '18 at 05:53

1 Answers1

0

One way to handle this on the SQL side would be to modify your query to the following:

SELECT COALESCE(_Provider_Number, '') AS _Provider_Number
FROM yourTable
...

Then, your database would automatically return empty string in case the provider number should be null.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • Thanks Tim. It did cross my mind to tackle from the query side but the problem with that is the query doesn't even return a row with null, it just returns an empty row so query result = 0 rows. – Matt Jun 26 '18 at 02:11
  • @Matt Then in this case you should really treat this as a SQL question, show us your sample data, and also the query. – Tim Biegeleisen Jun 26 '18 at 05:37