(main) Error: 1045-28000: Access denied for user [closed] - java

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 days ago.
Improve this question
When i update mariadb-java-client-2.7.1 to mariadb-java-client-3.1.2 i have warning...
[ WARN] (main) Error: 1045-28000: Access denied for user 'namecomputer'#'localhost' (using password: NO)
[ERROR] (main) error initializing pool connection - java.sql.SQLInvalidAuthorizationSpecException: (conn=781) Access denied for user 'namecomputer'#'localhost' (using password: NO)
java.sql.SQLInvalidAuthorizationSpecException: (conn=781) Access denied for user 'namecomputer'#'localhost' (using password: NO)
at org.mariadb.jdbc.export.ExceptionFactory.createException(ExceptionFactory.java:286)
at org.mariadb.jdbc.export.ExceptionFactory.create(ExceptionFactory.java:370)
at org.mariadb.jdbc.client.impl.ConnectionHelper.authenticationHandler(ConnectionHelper.java:287)
at org.mariadb.jdbc.client.impl.StandardClient.<init>(StandardClient.java:185)
at org.mariadb.jdbc.Driver.connect(Driver.java:70)
at org.mariadb.jdbc.pool.Pool.addConnection(Pool.java:197)
at org.mariadb.jdbc.pool.Pool.<init>(Pool.java:99)
at org.mariadb.jdbc.pool.Pools.retrievePool(Pools.java:36)
at org.mariadb.jdbc.MariaDbPoolDataSource.config(MariaDbPoolDataSource.java:63)
at org.mariadb.jdbc.MariaDbPoolDataSource.setUrl(MariaDbPoolDataSource.java:239)
at net.sf.l2j.commons.pool.ConnectionPool.init(ConnectionPool.java:23)
at net.sf.l2j.gameserver.GameServer.<init>(GameServer.java:149)
at net.sf.l2j.gameserver.GameServer.main(GameServer.java:125)
[ WARN] (main) Error: 1045-28000: Access denied for user 'root'#'localhost' (using password: NO)
[ERROR] (main) error initializing pool connection - java.sql.SQLInvalidAuthorizationSpecException: (conn=782) Access denied for user 'root'#'localhost' (using password: NO)
java.sql.SQLInvalidAuthorizationSpecException: (conn=782) Access denied for user 'root'#'localhost' (using password: NO)
at org.mariadb.jdbc.export.ExceptionFactory.createException(ExceptionFactory.java:286)
at org.mariadb.jdbc.export.ExceptionFactory.create(ExceptionFactory.java:370)
at org.mariadb.jdbc.client.impl.ConnectionHelper.authenticationHandler(ConnectionHelper.java:287)
at org.mariadb.jdbc.client.impl.StandardClient.<init>(StandardClient.java:185)
at org.mariadb.jdbc.Driver.connect(Driver.java:70)
at org.mariadb.jdbc.pool.Pool.addConnection(Pool.java:197)
at org.mariadb.jdbc.pool.Pool.<init>(Pool.java:99)
at org.mariadb.jdbc.pool.Pools.retrievePool(Pools.java:36)
at org.mariadb.jdbc.MariaDbPoolDataSource.config(MariaDbPoolDataSource.java:63)
at org.mariadb.jdbc.MariaDbPoolDataSource.setUser(MariaDbPoolDataSource.java:272)
at net.sf.l2j.commons.pool.ConnectionPool.init(ConnectionPool.java:24)
at net.sf.l2j.gameserver.GameServer.<init>(GameServer.java:149)
at net.sf.l2j.gameserver.GameServer.main(GameServer.java:125)
My code:
package net.sf.l2j.commons.pool;
import java.sql.Connection;
import java.sql.SQLException;
import net.sf.l2j.commons.logging.CLogger;
import net.sf.l2j.Config;
import org.mariadb.jdbc.MariaDbPoolDataSource;
public final class ConnectionPool
{
private static final CLogger LOGGER = new CLogger(ConnectionPool.class.getName());
private static MariaDbPoolDataSource _source;
public static void init()
{
try
{
_source = new MariaDbPoolDataSource();
_source.setUrl(Config.DATABASE_URL);
_source.setUser(Config.DATABASE_LOGIN);
_source.setPassword(Config.DATABASE_PASSWORD);
}
catch (SQLException e)
{
LOGGER.error("Couldnt initialize connection pooler.", e);
}
LOGGER.info("Initializing ConnectionPool.");
}
public static void shutdown()
{
if (_source != null)
{
_source.close();
_source = null;
}
}
public static Connection getConnection() throws SQLException
{
return _source.getConnection();
}
}

Related

SQLException : Access denied for user 'utilisateur1'#'localhost' (using password: YES) [duplicate]

This question already has answers here:
java.sql.SQLException: Access denied for user 'root'#'localhost' (using password: YES)
(31 answers)
SQLException: Access denied for user 'whatever'#'localhost'
(5 answers)
Access denied for User 'root'#'localhost' (using password: YES )
(5 answers)
MySQL ERROR 1045 (28000): Access denied for user 'bill'#'localhost' (using password: YES)
(43 answers)
Closed 2 years ago.
package com.exmaven2;
import java.sql.*;
public class MainApp
{
public static void main(String[] args)
{
String url = "jdbc:mysql://localhost:3306/baseune";
String userName = "utilisateur1";
String password = "password";
try {
java.sql.Connection con = DriverManager.getConnection(url, userName, password);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
Hello, I'm actually trying to connect to MySQL with a Maven project build in Eclipse IDE. I wrote this code that should let me connect to my server but I'm getting the error described in the title. I just began learning about databases and MySQL so I don't really know what to do. I already checked the privileges for 'utilisateur1' (somebody else posted the same question but this answer didn't work for me) and i have them all so I don't understand why it doesn't work.
could you please try this,
package com.exmaven2;
import java.sql.*;
public class MainApp
{
public static void main(String[] args)
{
String url = "jdbc:mysql://localhost:3306/baseune?useSSL=false";
String userName = "utilisateur1";
String password = "password";
try {
Connection con = DriverManager.getConnection(url, userName, password);
} catch (SQLException e) {
e.printStackTrace();
}
}
}

Error occuredjava.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I trying make connection between Mysql and my java program
My system configuration is:
Windows :10
64 bit
java version: 1.8
jar file: mysql-connector-java-8.0.19
My source code:
DatabaseConnectivity.java
package test;
import java.sql.*;
public class DatabaseConnectivity
{
Connection conn;
Connection getConnection(String database,String userName,String password)
{
try{
String url;
url="jdbc:mysql://localhost:8080/"+database;
Class.forName("com.mysql.cj.jdbc.Driver");
Connection conn=DriverManager.getConnection(url,userName,password);
System.out.println("Connected to database successfully");
}
catch(Exception e)
{
System.out.println("Error occured"+e);
}
return conn;
}
public DatabaseConnectivity()
{
}
}
Test.java
package test;
import java.sql.*;
import test.*;
class Test
{
public static void main(String args[])
{
try
{
DatabaseConnectivity db=new DatabaseConnectivity();
Connection conn=db.getConnection("records","root","dics");
System.out.println("Connected to database successfully");
}
catch(Exception e)
{
System.out.println(" Error occured"+e);
}
}//End of main method
}//End of class Test
I have set my classpath as
>set classpath
classpath="E:\softwares\java\jar files\mysql-connector-java-8.0.19.jar;";
I tried to run my code
javac DatabaseConnectivity.java
javac -classpath e:\user\java\jdbc\ Test.java
java -classpath e:\user\java\jdbc\ test.Test
It throws error
Error occuredjava.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver
Connected to database successfully
There were few problems.
The problem was when I set classpath by environment variables. And pass -classpath variable it overrides the default classpath environment variable.
So add jar file path to classpath option passed with java.exe
Class.forName() is not used anymore in mysql(mysql-connector-java-8.0.19). I
don't know why?
Source code:
E:\user\java\jdbc\test\DatabaseConnectivity.java
package test;
import java.sql.*;
public class DatabaseConnectivity
{
Connection conn;
Connection getConnection(String database,String userName,String password)
{
try{
String url;
url="jdbc:mysql://localhost:3306/"+database;
//Class.forName("com.mysql.jdbc.Driver");
//Class.forName("com.mysql.cj.jdbc.Driver");
conn=DriverManager.getConnection(url,userName,password);
System.out.println("Connected to database successfully");
}
catch(Exception e)
{
System.out.println("In Class DatabaseConnectivity Error occured"+e);
}
return conn;
}
public DatabaseConnectivity()
{
}
public static void main(String args[])
{
}
}
E:\user\java\jdbc\test\Test.java
package test;
import java.sql.*;
import test.*;
class Test
{
public static void main(String args[])
{
try
{
DatabaseConnectivity db=new DatabaseConnectivity();
Connection conn=db.getConnection("test","root","dics");
Statement st = conn.createStatement();
String table = "CREATE TABLE Employee11(Emp_code integer, Emp_name varchar(10))";
st.executeUpdate(table);
System.out.println("Table creation process successfully!");
}
catch(Exception e)
{
System.out.println(" class Test Error occured"+e);
}
}//End of main method
}//End of class Test
Third problem, I was using mysql 8+ and my jar file version was 5+. Your mysql version and jar file version should be same. Now, It is 8 as you can see in the classpath.
Check the port number of mysql
Login to mysql -u root -p
mysql>show variables where variable_name="port";
It was 3306. As you can see in my question I was usnig default port number which is 8080. I must have changed it while mysql installation because some other application was already running on 8080(probably tomcat or wamp server).
To execute
E:\user\java\jdbc\test>javac -classpath "e:\softwares\java\jar files\mysql-connector-java-8.0.19.jar";e:\user\java\jdbc\; DatabaseConnectivity.java
E:\user\java\jdbc\test>javac -classpath "e:\softwares\java\jar files\mysql-connector-java-8.0.19.jar";e:\user\java\jdbc\; Test.java
E:\user\java\jdbc\test>java -classpath "e:\softwares\java\jar files\mysql-connector-java-8.0.19.jar";e:\user\java\jdbc\; test.Test
Connected to database successfully
Table creation process successfully!

Trying to get a java program to connect to a local Mysql Database on Mac

I'm trying to build an Jframe app that gets information from a local mysql database and fills in a list view in the GUI. I can't get the program to connect to the database. I'm on a Mac and I was wondering if it is something to with permissions in the OS or if I'm just missing something in the code.
package dataBaseConnection;
import java.sql.*;
import javax.swing.*;
public class DBConnection
{
public static Connection dbConnection()
{
try
{
String driver = "com.mysql.cj.jdbc.Driver";
String url = "jdbc:mysql://mysql#localhost:3306/login";
String username = "root";
String password = "TestTestTestTest";
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, username, password);
JOptionPane.showMessageDialog(null, "Connected to the database");
return conn;
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null, "Could not connect to the database...");
return null;
}
}
}
package dataBaseConnection;
import java.awt.EventQueue;
import java.sql.*;
import javax.swing.JFrame;
public class Login {
private JFrame frame;
public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
try
{
Login window = new Login();
window.frame.setVisible(true);
}
catch (Exception e)
{
e.printStackTrace();
}
}
});
}
DBConnection myConn = new DBConnection();
public Login()
{
initialize();
DBConnection.dbConnection();
}
private void initialize()
{
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
No matter what I try I can't find my problem. It will not connect to my local mysql database.
The Exception is: java.sql.SQLException: Access denied for user 'root'#'localhost' (using password: YES)
Try to check your credentials to the MySQL, check the username and password
Access denied for user 'root'#'localhost' (using password: YES)
, you can check using the terminal with the username and the password
$ mysql -u root -p
If you forget the password review How to reset it
I figured it out after I printed the error. It was two issues first one was the login password. Got that fixed. But I was getting a TimeZone error.
Second error: java.sql.SQLException: The server time zone value 'MDT' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the 'serverTimezone' configuration property) to use a more specifc time zone value if you want to utilize time zone support.
Got that fixed by passing the timeZone through the client with the url.
"jdbc:mysql://localhost:3306/login?useUnicode=true&characterEncoding=utf8&useSSL=false&useLegacyDatetimeCode=false&serverTimezone=UTC";
This fixed it.

Java-Mysql - Access denied for user 'root'#'localhost' (using password: YES) [duplicate]

This question already has an answer here:
java.sql.SQLException: Access denied for user 'root'#'localhost' (using password: YES)
(1 answer)
Closed 7 years ago.
I am using the fllowing code and get this error:
Access denied for user 'root'#'localhost' (using password: YES)
java.lang.NullPointerException
I used several solutions from the stackoverflow. But the problem is not resolved! Please provide your solution.
Inserts only once, but then I came across the above error.
My Java code:
package DBConnection;
import java.sql.Connection;
import java.sql.DriverManager;
import com.mysql.jdbc.PreparedStatement;
public class Main {
public static void main(String[] args) throws Exception {
insert();
}
public static void insert() throws Exception{
final String var1 = "test1";
final String var2 = "تست2";
final String var3 = "test.com";
try{
Connection conn = getConnection();
PreparedStatement inserted = (PreparedStatement) conn.prepareStatement("INSERT INTO wpsjim_target_sites (site_name_en,site_name_fa,site_address) VALUES('"+var1+"','"+var2+"','"+var3+"')");
inserted.execute();
}catch(Exception e){
System.out.println(e);
}finally{
System.out.println("Insert Completed!");
}
}
public static Connection getConnection() throws Exception{
try{
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/simjin";
String username = "root";
String password = "rootpass";
Class.forName(driver);
Connection conn = DriverManager.getConnection(url,username,password);
System.out.println("Connected");
return conn;
} catch(Exception e){
System.out.println(e.getMessage());
}
return null;
}
}
Update:
When i use e.printStackTrace(System.out); display the fllowing messages on console:
java.sql.SQLException: Access denied for user 'root'#'localhost' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:871)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1694)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1215)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2255)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2286)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2085)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:795)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:400)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:327)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at DBConnection.Main.getConnection(Main.java:34)
at DBConnection.Main.insert(Main.java:17)
at DBConnection.Main.main(Main.java:9)
java.lang.NullPointerException
i think there is nothing in your code that will cause this type error, as you can see in error
Access denied for user 'root'#'localhost' (using password: YES)
it shows that problem is with your user or password, so check once again that your user and password is correct if you are using password for database user.
Incorrect username or password causes the problem.
Normally the default password is null. If you are using a root password it means you should have put like this:
String username = "root";
String password = "";//without space

Error in main - java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:1099" "connect,resolve") [duplicate]

This question already has answers here:
Java RMI AccessControlException: access denied
(3 answers)
Closed 8 years ago.
I've been trying to run an RMI example but have been getting the above error on both linux and windows. I have seen people with same problem online but in different situations.
My server class is:
import java.rmi.*;
import java.rmi.server.*;
public class CityServerImpl extends UnicastRemoteObject implements CityServer {
CityServerImpl() throws RemoteException {
super();
}
public String getCapital(String country) throws RemoteException {
System.out.println("Sending return string now - country requested: " + country);
if (country.toLowerCase().compareTo("usa") == 0)
return "Washington";
else if(country.toLowerCase().compareTo("ireland") == 0)
return "Dublin";
else if (country.toLowerCase().compareTo("france") == 0)
return "Paris";
return "Don't know that one!";
}
public static void main(String args[]) {
try {
System.setSecurityManager(new RMISecurityManager());
System.out.println("Security manager set");
CityServerImpl cityServer = new CityServerImpl();
System.out.println("Instance of City Server created");
Naming.rebind("Capitals", cityServer);
System.out.println("Name rebind completed");
System.out.println("Server ready for requests!");
} catch(Exception exc) {
System.out.println("Error in main - " + exc.toString());
}
}
}
I put the interface, CityServer class and my client class into a folder and put the following into the terminal.
javac -cp . *.java
rmic CityServerImpl
rmiregistry &
java CityServerImpl
And I get back:
Security manager set
Instance of City Server created
Error in main - java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:1099" "connect,resolve")
The 'Naming.rebind("Capitals", cityServer);' appears to be the problem. I have found mentions of a policy file but I have been told that this should run fine without one. Both the client and server would be running on the same PC. Any idea on how to get around this?
You defined the RMISecurityManager, but you did not grant yourself permissions to execute the code. You can define a policy as specified here and pass that in one of the two ways.
java -Djava.security.policy=<path>
set this your code
System.setProperty("java.security.policy","<path>");
I recommend reading this tutorial from oracle.
This should be a duplicate of an old question.

Categories