473,508 Members | 2,263 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access denied for user 'root'@'localhost'

56 New Member
Expand|Select|Wrap|Line Numbers
  1. import java.sql.*;
  2.  
  3. public class DBConnect {
  4.  
  5.     private Connection con;
  6.     private Statement st;
  7.     private ResultSet rs;
  8.  
  9.     public DBConnect(){
  10.         try{
  11.             Class.forName("com.mysql.jdbc.Driver");
  12.             con = DriverManager.getConnection("jdbc:mysql://localhost:3306/DataBaseName","user_name","password");
  13.             st = con.createStatement();
  14.  
  15.         }catch(Exception ex){
  16.             System.out.println("Error: "+ex);
  17.         }
  18.  
  19.     }
  20.  
  21.     public void getData(){
  22.         try{
  23.             String query = "select * from  test";
  24.             rs = st.executeQuery(query);
  25.             System.out.println("Records from Database");
  26.             while(rs.next()){
  27.                 String name = rs.getString("name");
  28.                 String age = rs.getString("age");
  29.                 System.out.println("name: "+name+"  "+"age: "+age);
  30.             }
  31.         }catch(Exception ex){
  32.             System.out.println(ex);
  33.         }
  34.     } 
  35.  
  36. }
  37.  
i have watched a video demonstrating how to connect java netBeans to MySQL server
this code is written in the video, but when i run it, it gives me the error:
Error: java.sql.SQLException: Access denied for user 'user_name'@'localhost' (using password: YES)
java.lang.NullPointerException
what is the problem here ?
Jan 29 '14 #1
7 6212
zmbd
5,501 Recognized Expert Moderator Expert
It means that you used the wrong user_name/password combination to attempt a connection to the database.

Contact your DBA to determine the correct username and password.
Jan 29 '14 #2
Norgy
56 New Member
but i log in to the server with the same user_name and password
Jan 29 '14 #3
zmbd
5,501 Recognized Expert Moderator Expert
You're trying to tell me that ","user_name","password"); is your user name and password? I just figured that these were being used as place holders in the code instead of the real information (^_^)

Doesn't matter, because the error is quite clear, the account name and password you have actually used in the code is not correct for the type of connection you are attempting establish, there is no point in arguing this fact.

Contact your DBA to determine the correct username and password.
Jan 29 '14 #4
zmbd
5,501 Recognized Expert Moderator Expert
Sorry, something just occured to me, it's been a very long time since IT setup my test MYSQL database:

Verify that your MYSQL has a passphrase go to the directory where you installed mysql, and in the bin directory try to bring up mysql prompt using:
Expand|Select|Wrap|Line Numbers
  1. ./mysql –u root mysql 
If the login goes through without any problem, it means no passphrase is set.
You can use mysqadmin script to set/reset passphrase.
Expand|Select|Wrap|Line Numbers
  1. ./mysqladmin –u root passphrase "new passphrase"
Jan 29 '14 #5
Norgy
56 New Member
no ^_^ i mean that i sign in to the server with the same user name and password written in the code (which are not written here, i wrote only alternative names for them)
anyway, i made a new account with new password and edited the code with the new ones but nothing changed :(
and sometimes it gives me this error
Error: com.mysql.jdbc.exceptions.jdbc4.CommunicationsExce ption: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. java.lang.NullPointerException
Jan 29 '14 #6
Norgy
56 New Member
sorry, i have just noticed your last comment
actually, i don't understand what you mean by bringing up mysql prompt.
Jan 29 '14 #7
iAirplane
1 New Member
@Norgy
I have the same problem at the moment, I'm sure my password and username is correct but I get the same error, while with a different database on the same server I can connect with the same user.

Since this is a year old, have you solved the problem, and can you help me?
Feb 23 '15 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2936
by: Steve | last post by:
Hi, Yesterday I signed up for another dedicated linux server with the hosting company I use and I am having problems getting MySQL 4.1.3 working on it. I've tried just about everything I can...
3
5691
by: Ian | last post by:
The beginning of my assembly that I am getting the access error from looks like this. ********************************* Imports System.EnterpriseServices Imports System Imports...
3
2391
by: vincentw56 | last post by:
This is the first time I have tried this. What we have is a com object the generates keys. A developer here wrote a .Net wrapper in C# for this com object. I am trying to call her dll wrapper...
4
3883
by: Fabian von Romberg | last post by:
Hi, I have installed Sql Reporting Services on 2 machines, one is WIN 2000 PRO and the other one is WIN 2000 ADV. SERVER. When I try to access a report using the webbrowser, I get the following...
12
5075
by: Chad Crowder | last post by:
Hi all, I hope someone can give me a hand, because I'm out of ideas. I keep getting this message: Access to the path "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET...
6
4127
by: ASP.Confused | last post by:
I have an ASP.NET page writtein in VB that uses ADODB. I just had to force-install MDAC 2.8 after I tried to rollback to 2.6 (my web host uses this, and I wanted to be compatible with them.) I...
0
3519
by: ASP.Confused | last post by:
The old message looked a little stale, so I am re-posting it here. Anybody have any ideas of what I could do?!? The previous responses to this question are below. If you want to look at the...
1
2122
by: karthi84 | last post by:
hi, when i tried to open a new excel spread sheet from my web form i got this access denied page. can any one help me in solving this problem. Server Error in '/sk/ContractInvoice'...
8
6032
by: Jeremy Ames | last post by:
I am trying to move an application from my system to a new test system. I really should have tried an easier program first, but I didn't really have a chance. My application was originally written in...
1
2126
by: zlf | last post by:
Hello my website has role based access, and user without specific role assigned cannot access specific page in website. When the user try to access a page who has not been granted to access, the...
0
7231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7132
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7063
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5640
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5059
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4720
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3196
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
432
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.