This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have written an application to compare the data stored in Mysql database with the data entered in the textfield in Swings. If both do not match i want to throqw a popup.
But the comparision is not taking place properly. Even if both match the pop up is being shown.
I am doing the comparision for the text in the language Telugu which is stored in the database with charset UTF8 and entered in the GUi using a TTF font.
A result set has been used to retrieve values as String and the equals() method in String is used to check for equality.
After line 8 in that code, both ResultSet objects are set to before the first result. You must first call next() on both, and only if both return true can you check the Strings.
If you don't mind the following syntax you need to change only line 10:
If either ResultSet has no records or the strings don't match your insert statement's values will be set.
Deepak Rao wrote:Try converting the text in the GUI to the same format as the db string,UTF-8 before comparing it with equals().
byte strbytes = oldstring.getBytes("UTF-8");
String newstring = new String(strbytes, "UTF-8");
No, don't waste your time with that code. After it's run the two strings newstring and oldstring will always contain the same data, so it's a pointless waste of time. Not to mention it clutters up your code.
Joined: Feb 09, 2012
I tried putting rs.next() after each initialisation of result set objects but still i see that the comparision is not happening correctly....
I am using a text field for which i set a font in Swings . When i am comparing it with UTF-8 data do i need to do anything else to check for equality