473,668 Members | 2,446 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access denied for user 'root'@'localho st'

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.SQLExc eption: Access denied for user 'user_name'@'lo calhost' (using password: YES)
java.lang.NullP ointerException
what is the problem here ?
Jan 29 '14 #1
7 6272
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.jdbc 4.Communication sException: 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.NullP ointerException
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
2942
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 think of to login via the MySQL client but get a variation of the following error every time: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
3
5711
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 System.Collections Imports System.Configuration Imports System.Data Imports System.Data.Common Imports System.Reflection
3
2399
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 with my ASP.NET page and I get an access denied error. I can use the test Windows Form just fine, but not my ASP.NET form. This is all local to my machine. The error is below. Thanks. Vincent Here is the error that I get:
4
3908
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 error, this happens only if try access the report on the SERVER, it I try on my local machine, it works just fine. Any help will be much appreciated. Thanks in advance, Fabian von Romberg
12
5095
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 Files\projects_cig\e4e3b3da\3c20ac69" is denied. The error goes on to say that the ASP.NET is not authorized...
6
4135
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 had to manually install all of the ODBC drivers and the rest of the DLL's, and now I am getting "Access is Denied" errors on any page that uses ADODB. How do I fix it? I already gave the ODBC drivers in the folders in "c:\program files\common...
0
3532
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 original question, the subject line is: ADODB.NET and "Access Denied" I have an ASP.NET page writtein in VB that uses ADODB. I just had to
1
2135
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' Application. Access is denied. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
8
6041
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 ASP.NET 1.1, but was migrated to 2.0 during development. The reason this is an issue is because the application is using the Microsoft.Web.UI.WebControls.dll for the tree view and tab strip controls that didn't exist prior to 2.0. Well, that is...
1
2134
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 web site should redirect the user to an access denied page. Instead, now they are taken to the splash page to prompt user input username and password. How to redirect the user to an access denied page in that case? Thanks
0
8371
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8889
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8790
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7391
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6206
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5677
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4202
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2017
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1779
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.