在java中打印Variable值似乎很简单,但我无法正确执行此操作。 我有Mysql表,其中包含名字" fname" &安培;姓氏" lname"。连接到我的SQL后,我获取这些值并存储在变量中。然后问题开始......这里是,这是我的代码
console.log('User actions :', $scope.userActions);
这是它的输出
package signup;
import java.sql.*;
import java.util.Random;
import org.openqa.selenium.Keys;
public class Signup {
private static final String db_connect = "jdbc:mysql://localhost/test1" ;
private static final String uname = "username" ;
private static final String pass = "password" ;
private Connection conMethod(){
Connection conVar = null;
try{Class.forName("com.mysql.jdbc.Driver");conVar = DriverManager.getConnection(db_connect,uname,pass);}catch(SQLException e){e.printStackTrace();
}catch(ClassNotFoundException e){e.printStackTrace();}return conVar;}
public void selectMethod(){Statement query = null;
ResultSet rs1 = null;
Connection conVar2= conMethod();try{query = conVar2.createStatement();
rs1 = query.executeQuery("Select * from fnames2");
String[] fname=new String[500]; String[] lname=new String[500];
int a=0;while(rs1.next()){fname[a]=rs1.getString(2); lname[a]=rs1.getString(3); a++;}
String firstname = fname[1];
String lastname = lname[1];
String fullname = firstname+" "+lastname;
String email = firstname+lastname+"@yahoo.com";
System.out.println("first name is "+firstname);
System.out.println("last name is "+lastname);
System.out.println("full name is "+fullname);
System.out.println("email is "+email);
} catch(SQLException e){e.printStackTrace();}
}
public static void main (String args[]){Signup obj = new Signup();obj.selectMethod();}
}
你可以看到问题在于电子邮件变量。它应该打印PATRICIAALISHA@yahoo.com,但它正在打印一些东西" @ yahoo.comATRICIAALISHA" 。感谢
答案 0 :(得分:2)
输出与lastname
"ALISHA\r"
一致。当您打印它时(取决于您的操作系统),\r
字符会使光标返回到行的开头。在打印"last name is"
或"full name is"
的情况下,这对输出的外观没有影响,因为光标无论如何都会转到下一行。但它导致email
为"PATRICIAALISHA\r@yahoo.com"
,这意味着在它输出email is PATRICIAALISHA
之后,光标会返回到行的开头并用@yahoo.com
覆盖已存在的内容,这足以通过P覆盖文本。