我正在嘗試使用數(shù)據(jù)庫計數(shù)驗證固定長度的文件計數(shù),當(dāng)它與計數(shù)匹配時,pass 語句不會在 if 語句中執(zhí)行,但是它將轉(zhuǎn)到 else 語句。任何方向都會被應(yīng)用。以下是我的代碼: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); 執(zhí)行后,它在我的報告中的 else 語句中打印失敗。我調(diào)試了哪里可以看到在比較語句中它與計數(shù)匹配。我不確定我在這里缺少什么。
1 回答
哆啦的時光機(jī)
TA貢獻(xiàn)1779條經(jīng)驗 獲得超6個贊
嘗試這個
if(ubservicesCount.trim().toString().equalsIgnoreCase(String.ValueOf(fileCount)))
我認(rèn)為問題在于您正在使用 .equals 并將字符串對象與 int 進(jìn)行比較...
IE
boolean java.lang.String.equals(Object anObject)
將此字符串與指定對象進(jìn)行比較。當(dāng)且僅當(dāng)參數(shù)不為 null 并且是表示與此對象相同的字符序列的 String 對象時,結(jié)果才為真。
添加回答
舉報
0/150
提交
取消
