匹配的字符串不会在 if else 条件 java 中通过语句

Matched String is not going to Pass statement in the if else condition java

我正在尝试使用数据库计数来验证固定长度文件计数,当它与计数匹配时,pass 语句不会在 if 语句中执行,但是它会转到 else 语句。任何方向都将适用。

以下是我的代码:

static String ubservicesCount = "";

    String connectionUrl = "jdbc:sqlserver://"+strpServer+":"+strpPort+";databaseName="+strpDatabase+";IntegratedSecurity=true";

                // Declare the JDBC objects.  
                Connection con = null;  
                Statement stmt = null;  
                ResultSet rs = null;  

                Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");  
                con = DriverManager.getConnection(connectionUrl); 

                String SQL = strpQuery5+Qt+ProcessID+Qt;
                stmt = con.createStatement();  
                rs = stmt.executeQuery(SQL);  

                while (rs.next()) {
                    ubservicesCount = rs.getString(1);
                    System.out.println("UB servicesCount is " +ubservicesCount);
                }

                String st;
                BufferedReader Br = null;
                File objFile = new File(strPlanFile+NewFileNmae);
                Br = new BufferedReader(new FileReader(objFile));

                List<String> list = new ArrayList<String>();
                while ((st = Br.readLine()) != null) {

                    String arraylist = st;              

                    String RcdType = arraylist.substring(0, arraylist.length()-392);

                    list.add(RcdType);          

                }

                Set<String> unique = new HashSet<String>(list);
                for (String key : unique) {


                    if(key.trim().toString().equals("SALINE")){

                        System.out.println(key + ": " + Collections.frequency(list, key));

                        int fileCount = Collections.frequency(list, key);

                        if(ubservicesCount.trim().toString().equals(fileCount))

                            objReport.setValidationMessageInReport("PASS", "Flat File "+key+" count "+fileCount+" is Matched with Database ubdiagcodes Count "+ubservicesCount);                                                                  
                        else
                        {
                            objReport.setValidationMessageInReport("FAIL", "Flat File "+key+" count "+fileCount+" is not Matched with Database ubdiagcodes Count "+ubservicesCount);                

                        }                       
                    }                               
                }

                Br.close();             

执行后在我报告的else语句中打印失败。我调试了我可以在比较语句中看到它与计数匹配的地方。我不确定我在这里遗漏了什么。

试试这个

if(ubservicesCount.trim().toString().equalsIgnoreCase(String.ValueOf(fileCount)))

我认为问题在于您正在使用 .equals 并将字符串对象与整数进行比较...

布尔值java.lang.String.equals(Object anObject)

Compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.