- import java.sql.*;
-
-
public class DBConnect {
-
-
private Connection con;
-
private Statement st;
-
private ResultSet rs;
-
-
public DBConnect(){
-
try{
-
Class.forName("com.mysql.jdbc.Driver");
-
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/DataBaseName","user_name","password");
-
st = con.createStatement();
-
-
}catch(Exception ex){
-
System.out.println("Error: "+ex);
-
}
-
-
}
-
-
public void getData(){
-
try{
-
String query = "select * from test";
-
rs = st.executeQuery(query);
-
System.out.println("Records from Database");
-
while(rs.next()){
-
String name = rs.getString("name");
-
String age = rs.getString("age");
-
System.out.println("name: "+name+" "+"age: "+age);
-
}
-
}catch(Exception ex){
-
System.out.println(ex);
-
}
-
}
-
-
}
-
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 ?
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.
but i log in to the server with the same user_name and password
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.
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:
If the login goes through without any problem, it means no passphrase is set.
You can use mysqadmin script to set/reset passphrase. - ./mysqladmin –u root passphrase "new passphrase"
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
sorry, i have just noticed your last comment
actually, i don't understand what you mean by bringing up mysql prompt.
@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?
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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'...
|
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...
|
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...
|
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,...
| |
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...
|
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,...
|
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...
|
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,...
|
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...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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...
| |