I'm trying to create a JDBC application using Java and MySQL in Eclipse IDE and Ubuntu 20.04 OS.
I'm getting the very common error while connecting to database that is "java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)" and I've tried every possible solution from stack overflow answers, youtube videos, articles, etc. but nothing seems to work.
The error:
Image may be NSFW.
Clik here to view.
My java code:
package jdbcDemo;import java.sql.*;public class jdbcConnect { public static void main(String[] args) throws SQLException, ClassNotFoundException { Class.forName("com.mysql.cj.jdbc.Driver"); String url = "jdbc:mysql://localhost:3306/jdbcDemo"; String user = "root"; String pswd = "1234"; Connection con = DriverManager.getConnection(url, user, pswd); if(con == null) { System.out.println("Connection not established"); } else { System.out.println("Connection established"); } }}
Users in my database:
Image may be NSFW.
Clik here to view.
Databse information:
Image may be NSFW.
Clik here to view.
Connection details (screenshots of mysql workbench):
Image may be NSFW.
Clik here to view.Image may be NSFW.
Clik here to view.
I'm trying to access database through user "root" which has password "1234" and plugin is "mysql_native_password".I'm trying to make connection with jdbcDemo database which has student table.
I'm able to successfully access and manipulate database using the same user and password through CLI and Workbench but getting the same error again and again in JDBC.
Some of the solutions that I've tried till now that didn't work:
- Creating new user with all privileges
- re installing mysql server
- creating database via mysql workbench
- changing plugin of the users
- tried all different ways to write the url
- different types of connections (tci/ip, local socket/pipe)
All the solutions are either outdated, not working or specific to windows operating system.
Please suggest some solutions to solve this issue in Ubuntu 20.04 or different alternatives to do this task (remote databse, etc.)
Thanks in advance !