当前位置: 技术问答>java相关
这两个字符串为什么不相等?
来源: 互联网 发布时间:2015-06-29
本文导语: Name = cardNumber value = "1234567"; …… String cardNumber = request.getParameter("cardNumber"); …… System.out.println("trim before:" + cardNumber); cardNumber = cardNumber.trim(); System.out.println("trim ago: " + cardNumber); System.out.println(String.value...
Name = cardNumber value = "1234567";
……
String cardNumber = request.getParameter("cardNumber");
……
System.out.println("trim before:" + cardNumber);
cardNumber = cardNumber.trim();
System.out.println("trim ago: " + cardNumber);
System.out.println(String.valueOf(cardNumber.compareTo("1234567")));
输出结果:
trim before:1234567
trim ago:1234567
-3
提问:这两个字符串为什么不相等?
……
String cardNumber = request.getParameter("cardNumber");
……
System.out.println("trim before:" + cardNumber);
cardNumber = cardNumber.trim();
System.out.println("trim ago: " + cardNumber);
System.out.println(String.valueOf(cardNumber.compareTo("1234567")));
输出结果:
trim before:1234567
trim ago:1234567
-3
提问:这两个字符串为什么不相等?
|
String sql = "select mailbox.password from profile,mailbox where profile.userid = mailbox.userid and profile.userid = ? and birthday = ? and certificateType = ? and cardNumber = ? ";
Mysql mysql = new Mysql(sql);
mysql.setString(1,userid);
mysql.setString(2,birthday);
mysql.setInt(3,Integer.parseInt(certificateType));
mysql.setString(4,cardNumber.trim());
ResultSet rs = mysql.executeQuery();
String newpass = null;
if(rs.next()) {
newpass = rs.getString("password");
///////////////////////////////////
试试了
Mysql mysql = new Mysql(sql);
mysql.setString(1,userid);
mysql.setString(2,birthday);
mysql.setInt(3,Integer.parseInt(certificateType));
mysql.setString(4,cardNumber.trim());
ResultSet rs = mysql.executeQuery();
String newpass = null;
if(rs.next()) {
newpass = rs.getString("password");
///////////////////////////////////
试试了