gpt4 book ai didi

java - NetBeans 表示用户 'root' @'localhost' 的访问被拒绝(使用密码 : YES))

转载 作者:行者123 更新时间:2023-11-29 18:21:42 25 4
gpt4 key购买 nike

我是java和开发的新手。我使用 NetBeans 8.0 和查询浏览器 1.1.2 创建数据库和表。输入用户详细信息后点击登录按钮后,将显示一条消息,如下所示

java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)

我使用查询浏览器创建了数据库,因为我对 MYSQL 工作台比查询浏览器还陌生。

下面是Home_Page代码

public class Home_Page extends javax.swing.JFrame {

public String User;
Model.JDBC j=new JDBC();

public Home_Page(String U_ID) {
initComponents();

User=U_ID;
Toolkit t = Toolkit.getDefaultToolkit();
Dimension d = t.getScreenSize();
int w = (int) d.getWidth();
int h = (int) d.getHeight()-40;
setBounds(0, 0, w, h);
jLabel2.setText(new Controler.getDate().date());
time();
jLabel3.setText(U_ID);
ResultSet rs;

try {

rs = j.getData("select ulevel from user U_ID='"+U_ID+"'");

if(rs.next()==true){

if(rs.getString(1).equals("Admin")){

home.setEnabled(true);
EMPLOYEE.setEnabled(true);
employee.setEnabled(true);
user.setEnabled(true);
machine.setEnabled(true);
branch.setEnabled(true);

}else if(rs.getString(1).equals("user")){


home.setEnabled(true);
EMPLOYEE.setEnabled(false);
employee.setEnabled(false);
user.setEnabled(false);
machine.setEnabled(false);
branch.setEnabled(false);


}else{
System.out.println("else");

}
}

} catch (Exception ex) {
Logger.getLogger(Home_Page.class.getName()).log(Level.SEVERE, null, ex);
}

}

public void time() {
new Thread(new Runnable() {

public void run() {
while (true) {
String times = new Date().toString();
String h = times.split(" ")[3];
jLabel1.setText(h);
try {
Thread.sleep(60);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}).start();
}

@SuppressWarnings("unchecked")

private void branchActionPerformed(java.awt.event.ActionEvent evt) {

jDesktopPane1.removeAll();
Branch b=new Branch();
jDesktopPane1.add(b);
b.setVisible(true);
jDesktopPane1.updateUI();
// TODO add your handling code here:
}
public void clear() {

this.dispose();

}
private void logoutActionPerformed(java.awt.event.ActionEvent evt) {

java.awt.Toolkit.getDefaultToolkit().beep(); int t = JOptionPane.showConfirmDialog(null, "Are You Sure...?");
if(t==JOptionPane.YES_OPTION){
this.dispose();
clear();
new Viewer.login().setVisible(true);
}
else if(t==JOptionPane.NO_OPTION)
{


}
else
{

}
}

private void userActionPerformed(java.awt.event.ActionEvent evt) {

jDesktopPane1.removeAll();
User_ u=new User_();
jDesktopPane1.add(u);
u.setVisible(true);
jDesktopPane1.updateUI();
// TODO add your handling code here:
}

private void employeeActionPerformed(java.awt.event.ActionEvent evt) {

jDesktopPane1.removeAll();
Employee_ emp=new Employee_();
jDesktopPane1.add(emp);
emp.setVisible(true);
jDesktopPane1.updateUI();
// TODO add your handling code here:
}

private void machineActionPerformed(java.awt.event.ActionEvent evt) {

jDesktopPane1.removeAll();
machine_ m = new machine_();
jDesktopPane1.add(m);
m.setVisible(true);
jDesktopPane1.updateUI();
// TODO add your handling code here:
}

private void homeActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
}

private void EMPLOYEEActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
}

public static void main(String args[]) {


Calendar expiry = Calendar.getInstance();
expiry.set(2013, 9 , 27,0,0); // Expire at 31 Jan 2010
Calendar now = Calendar.getInstance();
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Home_Page(" ").setVisible(true);
}
});
}

}

下面是我的登录表单代码

public class login extends javax.swing.JFrame {

public login() {
initComponents();
}

@SuppressWarnings("unchecked")

private void loginActionPerformed(java.awt.event.ActionEvent evt) {

if (eid.getText().trim().length() == 0 | pwd.getPassword() == null) {
JOptionPane.showMessageDialog(null, "Username or Password cannot be blank", "Error", 0);
} else {
try {
ResultSet rs = new DBG1().getData("select * from user where eid = '" +eid.getText() + "'");
Vector v = new Vector();
if (rs.next()) {
v.add(rs.getString(1));
}
if (v.isEmpty()) {
JOptionPane.showMessageDialog(null, "Invalid Username or Password", "Error", 0);
eid.setText("");
pwd.setText("");
eid.grabFocus();
} else {
ResultSet rs1 = new DBG1().getData("select * from user where eid ='" + eid.getText() + "'");
while (rs1.next()) {
String type = (rs1.getString(3));

if (eid.getText().trim().equalsIgnoreCase(rs1.getString("eid")) && pwd.getText().equals(rs1.getString("pwd")) && type.equals("Admin")) {
this.dispose();
new Home_Page(eid.getText()).setVisible(true);
// new Home_Page(eid.getText()).setVisible(true);
} else if (eid.getText().trim().equalsIgnoreCase(rs1.getString("eid")) && pwd.getText().equals(rs1.getString("pwd")) && type.equals("user")) {
this.dispose();
new Home_Page(eid.getText()).setVisible(true);

}
else {
JOptionPane.showMessageDialog(null, "Invalid Username or Password", "Error", 0);
eid.setText("");
pwd.setText("");
eid.grabFocus();
}
}
this.dispose();
}
} catch (Exception e) {
System.out.println(e);
}
}
// TODO add your handling code here:
}

private void cancelActionPerformed(java.awt.event.ActionEvent evt) {

new login().dispose();
System.out.println(pwd.getPassword());

System.out.println("Cleared");
this.dispose();
// TODO add your handling code here:
}

private void eidActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}


public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {

new Viewer.login().setVisible(true);
}
});
}

}

当我调试项目时,它应该首先运行加载窗口(此处未包含),然后运行登录窗口。输入详细信息并按登录按钮后,上述错误将显示在“POST_NEW 调试面板”中我已经研究并遵循了本网站之前发布的所有类似类型问题中提到的所有说明。但我处于这种情况。有人可以指出我应该在哪里修改我的代码或者我应该如何摆脱这个错误并进入我的项目的 Home_Page

最佳答案

尝试使用用户名 root 和密码为空。如果这不起作用,您可以尝试以下操作:Access denied for user 'username'@'localhost' (using password: YES) in C:\webdev\wamp\www\membershipSite\classes\Mysql.php on line 9

关于java - NetBeans 表示用户 'root' @'localhost' 的访问被拒绝(使用密码 : YES)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46521821/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com