Wensley Brands

Greenhorn
+ Follow
since Feb 08, 2018
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
5
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Wensley Brands

Paul Clapham wrote:It still remains to be answered why the stack trace you posted documents a connection attempt with no user ID and password:

Exception in thread "main" java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)



It also remains to be answered why the stack trace doesn't mention any of your code in it. In other words, what code tried to make that connection and why? I don't see any connection between that code (which is using a TimezoneDump class from the JDBC driver) and your JavaLesson36 class.



Ok, this answer was stuck in my head, so i did the following things:

I reinstalled Eclipse and went from JDK 8.0 to JDK 11.3

In advanced system settings -> enviromental variables... i created a new user variable to the jdk 11.3

And because you said something about TimeZoneDump class i synced my time zone in MySQL commandline with:  SET GLOBAL time_zone = 'SYSTEM';

It then gave me an error saying it can't recognize west europe time zone it represents mulitply country's, so i did SET GLOBAL time_zone = '+2:00'; <- which is weird i did this before i created this post and it did not work.

I did all of the above and now it's working 100 %.

Thanks for all the input guys i appreciate it, now i can finnaly sleep again and continue this tutorial :D

Paul Clapham wrote:

Wensley Brands wrote:Also when i test the connection on MySQL it says succes! This just makes 0 sense duo to the fact it connects smoothly in tutorial 34 :(



If "in tutorial 34" refers to some other person running code on some other computer, then that means nothing. However if it refers to some code running on your computer, then it's worth looking into. Do you have two different code examples which use the same user ID and password but, which when run on your computer, have different results with respect to being allowed to connect?

It's possible you didn't notice that the MySQL permissions system allows you to specify which hosts a user may connect from, and thus haven't set up your user ID to be allowed to connect from localhost.



I have tried typing GRANT ALL ON *.* TO 'sqladmin'@'localhost'; on my Command Line Client and it says query OK. But still does not grant me access.
In Java lesson 34 i connect to the MySQL database and i connect without any problems, the data shows up in my eclipse log.
The sqladmin account i use to log in with is made within MySQL workbench and i gave it all the privéleges possible just like someone told me to, instead of using the root account.



In Java lesson 36 i use the same connection code from JavaLesson34 but this time the data gets pulled and transfered into a Java tabel. Some how it will not let me connect and gives me the SQL exception below.



Paul Clapham wrote:

Wensley Brands wrote:No i installed it myself on my desktop pc. I will reinstall it to see if it fixes this issue. Yes i did use an ID and Password which is shown in the code to access the MySQL DB user: root pass: r00t1



It may be that the tutorial told you to use that ID and password in the code. However if you didn't actually go into MySQL as admin and set that ID up with that password, then it isn't going to work.

Reinstalling MySQL is not going to help. It's a relatively simple matter to manage users and their passwords in MySQL so that's the direction you should go in.



The complete code is now included in this post, hope it fits your sscce standard.

I have created another account called sqladmin with all the privéleges and instead of using:

conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/lahman2016","root", "r00t");

I now use:

conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/lahman2016","sqladmin", "SQLPASSWORD");

and still the same Exception.

Also when i test the connection on MySQL it says succes! This just makes 0 sense duo to the fact it connects smoothly in tutorial 34 :(

Tim Holloway wrote:

Wensley Brands wrote:Would it help to screenshot a certain part of MySQL settings ?



It would help a a lot more if you'd stop using media-intensive examples. Just copy-and-paste the text. No videos, no screenshots. No singing fairies and no dancing flowers. Not unless we ask specifically.

It's just a lot easier for us to read plain text (with code tags) than have to deal with a circus.

Also, Class.forName is long obsolete. You can completely delete that line.

For specifics on how to form MySQL JDBC URLS: https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-jdbc-url-format.html

It's a pretty "busy" page itself, but it's quite detailed.



That's exactly what i wanted to do when i first started the post but i am a new user i dont have any Pie's that allows me to post a lot of code lines, sorry for all the links!
Would it help to screenshot a certain part of MySQL settings ?

Paul Clapham wrote:

Wensley Brands wrote:Anyway could it be that MySQL settings are not correct?



It certainly could (for some definition of "not correct"). It's clear that your MySQL installation is set up with user IDs and passwords. I would expect that you did that at some point, or was somebody else involved in the setup? Anyway to use your MySQL you're going to have to provide a user ID and password which matches a user ID which it knows about.



No i installed it myself on my desktop pc. I will reinstall it to see if it fixes this issue. Yes i did use an ID and Password which is shown in the code to access the MySQL DB user: root pass: r00t1

Paul Clapham wrote:Hi Wensley, welcome to the Ranch!

You posted some code:



which gets a connection, using user ID "root" and an associated password. But on the other hand your error message:

MySQL wrote:Access denied for user ''@'localhost' (using password: NO)



which says that somebody tried to get a connection using no user ID and no password.

So it seems that the code you posted isn't the code which is causing the exception.

And no, I didn't watch the tutorial. Video is such a horribly linear format, whereas if it was a text-based tutorial I could just search for the relevant section.

EDIT: I see you edited your post to link to a text-based tutorial as well as the video tutorial. That's a useful change but it would also be useful in future if you could insert a comment (like this one) when you edit one of your posts.



Wow very weird, there was no reply button underneath my post until you 2 guys replied my bad sorry! Anyway could it be that MySQL settings are not correct?

When i try logging in with my sqladmin account instead of my root account both tutorial 34 and 36 wont work i get the vendor error:

SQL Exception: Access denied for user 'sqladmin'@'localhost' (using password: YES)
Vendor Error: 1045

FULL CODE IS IN THESE LINKS:

http://www.newthinktank.com/2012/04/java-video-tutorial-34/

http://www.newthinktank.com/2012/04/java-video-tutorial-36/

Hey guys, i am following this Java Tutorial 36 from Derek Banas on Youtube.

The problem:

When i try to acces the MySQL database with code from Java Tutorial 34 i can query the lahman2016 database without any problem and the data i pulled gets shown in the eclipse log.

When i try to acces the MySQL database with code from Java Tutorial 36 i get the exception code below

I am using a windows 10 operating system + MySQL 8.0

The only thing different in Java Tutorial 36 is that he wants to put the pulled data from MySQL into Java Tables, but that shouldn't cause this error.

EDIT: I have reinstalled MySQL and still have the same problem.

Also applied this https://stackoverflow.com/questions/50177216/how-to-grant-all-privileges-to-root-user-in-mysql-8-0/50197630 didnt work either.