我是新來的應用程序和從未使用過的數據庫,但知道它的基礎知識。 找到了在互聯網上製作簡單登錄頁面的代碼,但返回的輸出始終爲「不正確的憑證」。無法連接到Java數據庫應用程序
這裏是提交按鈕的代碼。
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");
}
}
,這裏是爲驗證碼LOGIN-
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;
}
這是我的phpmyadmin頁面級 enter image description here
仍然當我進入以「admin」的用戶名和密碼的輸出「不正確的憑證」。 請幫忙。 在此先感謝!
爲了更好地幫助更快,發佈[MCVE]或[短,自包含,正確示例](http://www.sscce.org/)。 –