私はアプリケーションを作成するのが初めてで、データベースは使用しませんでしたが、その基本を知っています。 インターネット上で簡単なログインページを作成するコードを見つけましたが、返される出力は常に「不正な認証情報」です。JavaアプリケーションでMySQLデータベースに接続できません
[送信]ボタンのコードは次のとおりです。
if(jTextField2.getText().length()==0) // Checking for empty field
JOptionPane.showMessageDialog(null, "Empty fields detected ! Please fill up all fields");
else if(jPasswordField1.getPassword().length==0) // Checking for empty field
JOptionPane.showMessageDialog(null, "Empty fields detected ! Please fill up all fields");
else{
String user = jTextField2.getText(); // Collecting the input
char[] pass = jPasswordField1.getPassword(); // Collecting the input
String pwd = String.copyValueOf(pass); // converting from array to string
if(validate_login(user,pwd))
JOptionPane.showMessageDialog(null, "Correct Login Credentials");
else
JOptionPane.showMessageDialog(null, "Incorrect Login Credentials");
}
}
、ここでこれは私が「管理者」としてユーザー名とパスワードを入力したときに enter image description here
PAGE-私のphpmyadminのは、まだ出力されている
private boolean validate_login(String username,String password) {
try{
Class.forName("com.mysql.jdbc.Driver"); // MySQL database connection
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mmtc_law?zeroDateTimeBehavior=convertToNull [root on Default schema]?" + "user=root&password=");
PreparedStatement pst = conn.prepareStatement("Select * from login where username=? and password=?");
pst.setString(1, username);
pst.setString(2, password);
ResultSet rs = pst.executeQuery();
if(rs.next())
return true;
else
return false;
}
catch(Exception e){
e.printStackTrace();
return false;
}
をlogin-検証するためのコードで"不正な資格情報"。 助けてください。 ありがとうございます!
、[MCVE]または[ショート、自己を投稿します含まれる、正しい例](http://www.sscce.org/)。 –