4

I am working on a small program right now and one of its functions is to read a set of string from a database and compare it to another string in the same table. If they are the same, it just presents one string, if they are different, it presents both strings.

On my development machine, this works as expected. When I install the application on a client's testing computer, the process behaves differently. Specifically, the strings return as the same on my computer, but they frequently return as different on my client's computer.

The code for this is simple:

if (!item.getDescription().equals(item.getBackDescription())) {
        item.setDescriptionDisplay(item.getDescription() + "   (" + item.getBackDescription() + ")");
    } else {
        item.setDescriptionDisplay(item.getDescription());
}

Here's screenshot of it happening (my computer's is on top):

From my computer From their computer

I have thought of and tried several things for this:

  • I am bundling JRE with the application, their computer does not have it installed. I have JRE installed on my computer. Wondering if there was an issues or difference with one of the runtimes, I uninstalled JRE (and JDK) on my computer to ensure it was using the bundled version in my copy of the application.

  • I wondered if there was an issue with the data that I was using to test with on my computer. I exported the tables that I am using form their machine and read them into my copy of the database to make sure the data is the same.

Other notes:

  • The data is not always wrong on their computer. The things that should be marked as different are and not everything that is supposed to be marked the same is marked incorrect.

Any help would be greatly appreciated, I have been messing with this for hours. Thanks.

loganhuskins
  • 1,399
  • 3
  • 15
  • 33
  • 2
    Could the encoding be different on the client? How are data inputted into application? – Vivin Paliath Jul 29 '15 at 18:30
  • Possibly, this is something I have not had to deal with before. How would I tell something like that? The data is read directly from the database. – loganhuskins Jul 29 '15 at 18:31
  • 1
    When you copy their data over, I'm assuming it works fine for you? Are both the description and "back description" saved in the database? – Vivin Paliath Jul 29 '15 at 18:32
  • Yes, both descriptions are stored in the database and when I copy the data over it works fine for me. I just added a clarification: I did not back up the database itself, rather exported the tables that I am reading from and imported into my copy of the database. – loganhuskins Jul 29 '15 at 18:34
  • 1) I'm assuming the client inputs data directly into the database? 2) How did you export the data? 3) What kind of database is it? – Vivin Paliath Jul 29 '15 at 18:35
  • See here for details about how to set the default encoding when you start your binary: http://stackoverflow.com/q/361975/3788176. Try running it with the same explicit encoding on both machines, see if that makes it work as expected. – Andy Turner Jul 29 '15 at 18:37
  • 1) Off the top of my head, I am not sure. I assume that's the case though. 2) Using SQL Server's 'generate scripts' tools. 3) SQL Server 2008 r2 When I actually go into the database on the client's computer and compare the values using SQL, the database shows them as the same. – loganhuskins Jul 29 '15 at 18:38
  • Another important question, I think, is are both the machines using a similar OS, that is Windows to Windows for example. I know that it is possible to use one set of escape characters for example in your Java code and it works fine, but won't work on a separate machine. Check to see that is not the case, as I know that for Windows and Unix for example, the escape character "0" won't act the same. – SomeStudent Jul 29 '15 at 18:38
  • Andy - Thanks for the link, I will look into that right now. – loganhuskins Jul 29 '15 at 18:39
  • Ageoffan - They are both Windows 7 64 bit – loganhuskins Jul 29 '15 at 18:40
  • Can you show how you are reading in values from the database? – Vivin Paliath Jul 29 '15 at 18:41
  • I can't copy it all over because it is sort of a lot but it goes like this: 1) create a prepared statement that selects all from the table into a ResultSet 2) iterate through the ResultSet, passing the result to a function depending on a flag in the table 3) that function runs the reads it into an object and depending on the flag runs comparisons like this on it accordingly. These string are the only issues, all non-string data types compare fine. – loganhuskins Jul 29 '15 at 18:48
  • Leading or trailing whitespace is likely. Or case sensitivity. Or characters which look similar but are not the same, either because they're from different parts of Unicode or just because 0 looks like O in many fonts. – keshlam Jul 29 '15 at 19:11

1 Answers1

1

Have you tried to remove some blank spaces? Try:

if (!item.getDescription().trim().equals(item.getBackDescription().trim())) {
        item.setDescriptionDisplay(item.getDescription() + "   (" + item.getBackDescription() + ")");
    } else {
        item.setDescriptionDisplay(item.getDescription());
}
messivanio
  • 2,263
  • 18
  • 24
  • I will try this right now, but I don't think it's an issue with their being too much white space if that's what you're getting at. I already tried replacing all the white space with underscores just to test that visually. – loganhuskins Jul 29 '15 at 18:41
  • This solved the issue. It's odd, because when I compare the actual values in the database the compare as teh same. Any idea why this'd be the case? Thank you. – loganhuskins Jul 29 '15 at 20:01
  • 1
    Some database vendors trim strings for you. – Tobb Jul 29 '15 at 22:02
  • They are using the same version of the same database and the data in the tables is exactly the same. They are SQL Server 2008 r2. I could see that causing it if they were different, but it's odd in this case. – loganhuskins Jul 30 '15 at 18:41
  • 1
    The databases may be configured differently. For example, ANSI_PADDING may be different in the two environments. Take a look at https://support.microsoft.com/en-us/kb/316626 and https://support.microsoft.com/en-us/kb/231830. But this is only one of several possibilities. – messivanio Jul 30 '15 at 19:09