gpt4 book ai didi

java - 匹配的字符串不会在if else条件java中传递语句

转载 作者:行者123 更新时间:2023-12-02 10:18:50 24 4
gpt4 key购买 nike

我正在尝试使用数据库计数验证固定长度文件计数,其中当它与计数匹配时,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 并将 String 对象与 int 进行比较...

boolean 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.

关于java - 匹配的字符串不会在if else条件java中传递语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54483328/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com