我爲我們公司創建了一個應用程序。起初,我試圖在MySQL-xampp的數據庫中創建沒有密碼的密碼,並且它工作正常。現在,我的問題是我把密碼在我的數據庫,我的應用程序現在已經拋出了我這個錯誤,每當我登錄:Netbeans和mysql通信
SQL值java.sql.SQLException:拒絕訪問用戶 「根」 @'CITSP- MOB7' (使用密碼:YES)
我也得到一個錯誤的連接我的數據庫:
無法連接。無法建立與 的連接jdbc:mysql // localhost:3306/mydb using com.mysql.jdbc.Driver(Access denied for user'root'@'CITSP-MOB7'(using password:YES))。
這裏是我的數據庫連接代碼:
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://192.168.1.112:3306/citsp";
static final String USER = "root";
static final String PASS = "mypassword";
try{
Class.forName("com.mysql.jdbc.Driver");
}catch(ClassNotFoundException ex){
}
//STEP 3: Open a connection
System.out.println("Connecting to database...");
conn = DriverManager.getConnection(DB_URL,USER,PASS);
//STEP 4: Execute a query
System.out.println("Creating statement...");
stmt = conn.createStatement();
有人可以幫我解決連接問題? 您的回答將不勝感激。提前致謝! :)
你在你的數據庫設置一個密碼,讓您的應用程序知道它應該在訪問密碼之前知道密碼。請發佈您的java代碼[只有與mysql部分的連接] – 1000111
首先,您應該設置除root以外的其他用戶。 –
Hi @Subrata Dey,這是我的代碼:static final String JDBC_DRIVER =「com.mysql.jdbc.Driver」; static final String DB_URL =「jdbc:mysql:// localhost:3306/citsp」; static final String USER =「root」; static final String PASS =「mypassword」; – nhix