mysql - How to verify whether localhost username and password is correct or not using java? -
i've been looking verification of localhost(in case xampp) username , password i.e 'root' , '' (null). suppose user changed localhost username , password how can verify using java + sql query.
//database credentials public static connection conn = null; public static statement stmt = null; public static string jdbc_driver = "com.mysql.jdbc.driver"; public static string db_url = "jdbc:mysql://localhost/"; class.forname("com.mysql.jdbc.driver"); conn = drivermanager.getconnection(db_url); system.out.println("driver loaded"); conn = drivermanager.getconnection( db_url , lh_username , lh_password); stmt = conn.createstatement();
is there way can boolean result while executing 1 of above
you can surround
conn = drivermanager.getconnection( db_url , lh_username , lh_password);
whit try catch block in way:
try { conn = drivermanager.getconnection( db_url , lh_username , lh_password); } catch(sqlexception e){ if(e.getmessage().startswith("access denied user")){ system.out.println("error: nont valid user or password"); //you can add return false if want return false; } }
Comments
Post a Comment