public class Login {
protected static String user, pass, host;
Object conn;
public void Login() throws SQLException
{
try {
Class.forName ("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
System.out.println ("Could not load the driver");
}
Scanner sc = new Scanner(System.in);
Console console = System.console();
System.out.println("Please Enter Username");
user = sc.next();
System.out.println("Please Enter Password");
pass = sc.nextLine();
System.out.println("Please Enter Host/IP Address");
host = sc.next();
System.out.println("Attempting Log In");
Connection conn = (Connection) DriverManager.getConnection
("jdbc:mysql://"+host+":3306/chessdb", user, pass);
有点帮助,您正在网上四处查看,以阻止在控制台窗口中显示的密码。是否有一种简单的方法,要么根本不显示输入的文本,要么仅显示一个仅覆盖密码字段输入的星号?
使用readPassword()
方法。
而不是像使用扫描仪
System.out.println("Please Enter Password");
pass = sc.nextLine();
使用:
System.out.println("Please Enter Password");
char[] passString = Console.readPassword();
String pass = new String(passString );
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句