Caused by: java.sql.SQLException: Access denied - java

I have a Java application and I want to access my local database which is a MySQL database, but I have this exception:
Caused by: java.sql.SQLException: Access denied for user
'root'#'localhost' (using password: YES)
I tried to execute this command from MySQL command line client:
mysql> GRANT ALL PRIVILEGES ON mydb.* TO 'root'#'localhost' IDENTIFIED BY 'myPass';
But it didn't solve my problem and the exception still appears.
This my connection configuration "database.properties" file:
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc\:mysql\://localhost\:3306/mydb
jdbc.username=root
jdbc.password=myPass

Related

Access denied in flyway on deploy to the heroku

When attempting to deploy, even with certain password and user, flyway is not allowed to migrate. Can someone help me? follows log error below.
2018-12-10 02:07:55.578 ERROR 4 --- [ main]
o.a.tomcat.jdbc.pool.ConnectionPool : Unable to create initial
connections of pool. 2018-12-10T02:07:55.579896+00:00 app[web.1]:
2018-12-10T02:07:55.579898+00:00 app[web.1]: java.sql.SQLException:
Access denied for user ''#'ec2-54-91-197-4.compute-1.amazonaws.com'
(using password: YES) 2018-12-10T02:07:55.579899+00:00 app[web.1]: at
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
~[mysql-connector-java-8.0.13.jar!/:8.0.13]
2018-12-10T02:07:55.579901+00:00 app[web.1]: at
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
~[mysql-connector-java-8.0.13.jar!/:8.0.13]
2018-12-10T02:07:55.579903+00:00 app[web.1]: at
com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
~[mysql-connector-java-8.0.13.jar!/:8.0.13]
Invocation of init method failed; nested exception is
org.flywaydb.core.internal.exception.FlywaySqlException:
2018-12-10T02:07:55.611900+00:00 app[web.1]: Unable to obtain
connection from database: Access denied for user
''#'ec2-54-91-197-4.compute-1.amazonaws.com' (using password: YES)
2018-12-10T02:07:55.611902+00:00 app[web.1]:
2018-12-10T02:07:55.611904+00:00 app[web.1]: SQL State : 28000
2018-12-10T02:07:55.611906+00:00 app[web.1]: Error Code : 1045
2018-12-10T02:07:55.611908+00:00 app[web.1]: Message : Access
denied for user ''#'ec2-54-91-197-4.compute-1.amazonaws.com' (using
password: YES) 2018-12-10T02:07:55.611909+00:00 app[web.1]:

jcifs.smb.SmbException: Failed to connect: 0.0.0.0<00>/172.16.1.181

I am getting an error while connecting to shared folder on remote machine.
I have configured :
Shared folder path as : //172.16.1.181/myReports
Domain Name : testLab.net
User and Password is also provided which are in same domain as 'testlab.net'
I am using JCIFS verison 1.3.17
Error is as :
Caused by: jcifs.smb.SmbException: Failed to connect: 0.0.0.0<00>/172.16.1.181
jcifs.util.transport.TransportException
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:210)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at jcifs.util.transport.Transport.readn(Transport.java:29)
at jcifs.smb.SmbTransport.peekKey(SmbTransport.java:388)
at jcifs.smb.SmbTransport.negotiate(SmbTransport.java:288)
at jcifs.smb.SmbTransport.doConnect(SmbTransport.java:319)
at jcifs.util.transport.Transport.run(Transport.java:241)
at java.lang.Thread.run(Thread.java:748)
at jcifs.util.transport.Transport.run(Transport.java:258)
at java.lang.Thread.run(Thread.java:748)
at jcifs.smb.SmbTransport.connect(SmbTransport.java:309)
at jcifs.smb.SmbTree.treeConnect(SmbTree.java:156)
at jcifs.smb.SmbFile.doConnect(SmbFile.java:911)
at jcifs.smb.SmbFile.connect(SmbFile.java:954)
at jcifs.smb.SmbFile.connect0(SmbFile.java:880)
at jcifs.smb.SmbFile.queryPath(SmbFile.java:1335)
at jcifs.smb.SmbFile.exists(SmbFile.java:1417)
at com.sv.tools.ppsfinder.svc.sharedfolder.SharedFolderReader.getFoldersList(SharedFolderReader.java:44)
... 4 more
Can anybody suggest why 'Failed to connect: 0.0.0.0<00>/172.16.1.181' may occurring ?
Update :
I can ping remote machine from my machine and I can open shared folder if I paste the same url in Win+R (Run prompt).

Exception While Connecting to mysql db with play framework

I am working with PlayFramework (2.3.x) application. I wanted to connect to a mysql db. Below is the configuration that I had given in application.conf:
db.default.driver="com.mysql.jdbc.Driver"
db.default.url="jdbc:mysql://localhost/mydb"
db.default.jndiName=DefaultDS
db.default.username=root
db.default.password=root
db.default.logStatements=true
jpa.default=defaultPersistenceUnitName
When I run the application I am getting the following exception
Oops, cannot start the server.
Configuration error: Configuration error[Cannot connect to database [default]]
at play.api.Configuration$.play$api$Configuration$$configError(Configuration.scala:94)
at play.api.Configuration.reportError(Configuration.scala:743)
at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:247)
at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:238)
at scala.collection.immutable.List.map(List.scala:273)
at play.api.db.BoneCPPlugin.onStart(DB.scala:238)
at play.api.Play$$anonfun$start$1$$anonfun$apply$mcV$sp$1.apply(Play.scala:91)
at play.api.Play$$anonfun$start$1$$anonfun$apply$mcV$sp$1.apply(Play.scala:91)
at scala.collection.immutable.List.foreach(List.scala:381)
at play.api.Play$$anonfun$start$1.apply$mcV$sp(Play.scala:91)
at play.api.Play$$anonfun$start$1.apply(Play.scala:91)
at play.api.Play$$anonfun$start$1.apply(Play.scala:91)
at play.utils.Threads$.withContextClassLoader(Threads.scala:21)
at play.api.Play$.start(Play.scala:90)
at play.core.StaticApplication.<init>(ApplicationProvider.scala:55)
at play.core.server.NettyServer$.createServer(NettyServer.scala:253)
at play.core.server.NettyServer$$anonfun$main$3.apply(NettyServer.scala:289)
at play.core.server.NettyServer$$anonfun$main$3.apply(NettyServer.scala:284)
at scala.Option.map(Option.scala:146)
at play.core.server.NettyServer$.main(NettyServer.scala:284)
at play.core.server.NettyServer.main(NettyServer.scala)
Caused by: java.sql.SQLException: Access denied for user ''#'localhost' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:998)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3847)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3783)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:871)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1665)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1207)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2249)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2280)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2079)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:794)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:400)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:399)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:325)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at com.jolbox.bonecp.BoneCP.obtainRawInternalConnection(BoneCP.java:363)
at com.jolbox.bonecp.BoneCP.<init>(BoneCP.java:416)
at com.jolbox.bonecp.BoneCPDataSource.getConnection(BoneCPDataSource.java:120)
at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:240)
... 18 more
I have my db created and I am able to use with mysql console.
I have my persistence.xml placed in my conf/META-INF. Below is the persistence.xml
I have root user with all privileges.
Could anyone help me with this?
According to the docs for Play 2.3.x, the correct configuration is db.default.user and not db.default.username. That is probably the cause of the exception. So change your configuration to:
db.default.driver="com.mysql.jdbc.Driver"
db.default.url="jdbc:mysql://localhost/mydb"
db.default.jndiName=DefaultDS
db.default.user=root
db.default.password=root
db.default.logStatements=true
jpa.default=defaultPersistenceUnitName
You are not passing a login, as indicated by the line
Caused by: java.sql.SQLException: Access denied for user ''#'localhost' (using password: YES)

Access denied for user 'root'#'localhost' (using password: YES) on JavaEE project code

These days I do exercise about JDBC.When the Java project connect the MySQL,then it's Ok.But the JavaEE project which run on MyEclipse cann't connect to MySQL,these is the error messages:
严重: create connection error
java.sql.SQLException: Access denied for user 'root'#'localhost' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4074)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4006)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1694)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1244)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2397)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2430)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2215)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:813)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.GeneratedConstructorAccessor14.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:399)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:334)
at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:142)
at com.alibaba.druid.filter.stat.StatFilter.connection_connect(StatFilter.java:211)
at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:136)
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1271)
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1325)
at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:1215).
The import thing:I try to grand,restart the mysql and so on.But all of them are failed.
MySql default password is root try it, or using the "" for password.
Thanks everyone.I solve my problem.Followings are the ways:
(1:To install a newest MyEclipse software.)
2.To install a newest Tomcat7.0.64.(Warning:this is the most important way I have to solve my problem).

Why am I getting an "Access denied to 'localhost'" error?

I've been trying to log in to mysql, with a username of "root", and a password of "pass", and this is the stacktrace I get when I try to run a java program using a database:
Apr 12, 2014 4:51:41 PM carselectionui.CarSelectionUIWDB main
SEVERE: null
java.sql.SQLException: Access denied for user 'root'#'localhost' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4120)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4052)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:925)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1704)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1250)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2465)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2498)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2283)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:822)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:404)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:317)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
at carselectionui.CarSelectionUIWDB.main(CarSelectionUIWDB.java:597)
Exception in thread "main" java.lang.NullPointerException
at carselectionui.CarSelectionUIWDB.main(CarSelectionUIWDB.java:604)
The strange thing is, I was actually able to connect to the DB when I was working on the code a couple of weeks ago, but ever since I rebooted my computer, I'm getting the access denied error again. I tried using no password, thinking that the password reset on reboot, but I still get the same error. I get this error anytime I try to connect to the database, so I know that it's not the code that's the problem.
I'm using Windows 7, and these are my path values:
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;
C:\Go\bin;
C:\Program Files (x86)\MySQL\MySQL Utilities 1.3.6;C/wamp/bin/mysql/mysql5.6.12/bin/mysql.exe;
C/Program Files (x86) /MySQL/Connector J 5.1.29/mysql-connector-java-5.1.29-bin.jar;
C:/Users/pnflift8191/;
C:/Program Files (x86)/MySQL/Connector J 5.1.29/mysql-connector-java-5.1.29-bin.jar
Just realized that I have mysql-connector on there twice, but I know that's not the reason this isn't working, because it still didn't work before I accidentally added it on there again.
EDIT: I've also tried connecting through the command line and MYSQL workbench, and I still get an error.
Try running the program as an administrator [right click the jar or whatever and run as admin]. If you are using eclipse as an IDE you should run eclipse with administrator privileges [same process].
If that still doesn't work, ensure that the username and password are correct.
The way that I ended up solving this problem is to:
1: Stop the MySQL service
2: type: mysqld -skip--grant--tables in the command line
3: I'm able to start MySQL.
The only problem with this method is that this works for any username and password, but at least I can work on MySQL.

Categories

Resources