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.
Related
When attempting to do this in my code:
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/MazeJumperLeaderboardDB", "root", "password");
I always seem to get this error no matter what I try:
java.sql.SQLException: java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:988)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:974)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919)
at com.mysql.jdbc.ConnectionImpl.buildCollationMapping(ConnectionImpl.java:1062)
at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3556)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2513)
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:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
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:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
... 61 more
I am using Java NetBeans IDE 8.2 and using MySQL Connector Java 8.0.18.
I have looked at other questions, notably this one:
ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long on connect to MySQL
But, doing this resulted in the same 'java.sql.SQLException: java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long' error.
Furthermore, I seem to be able to connect to my database driver just fine, but when attempting to connect to the MySQL server, it displays an error message with the same error yet again.
I'm really not sure what else to try at this point, so any help would be greatly appreciated!
I managed to (finally) solve my issue.
The problem was with the pre-installed JDBC driver on NetBeans. The pre-installed JDBC driver was of version 5.1.23, which is outdated and did not match up with my installed JDBC driver from the MySQL website.
So, what I did was:
I deleted the pre-installed driver in the 'Libraries' folder on NetBeans (under your project, the libraries folder), then right clicked on my project, selected 'Properties', then 'Libraries', then I clicked 'Add JAR/Folder', then browsed through my system files and searched for the latest version of MySQL Connector that I had downloaded (Connector/J 8.0.18), and then I added the .zip file. Then I went over to the services tab, and re-established the connection to the database and drivers using the SAME MySQL Connector version, and then it worked and stopped giving me this error.
When connecting to MySQL, I get an error (see below).
Click here for code
I get this output:
run:
Now connecting to databse...
java.sql.SQLException: java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long
java.sql.SQLException: java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:988)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:974)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919)
at com.mysql.jdbc.ConnectionImpl.buildCollationMapping(ConnectionImpl.java:1062)
at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3556)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2513)
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:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
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:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at dbms_basic.Dbms_Basic.main(Dbms_Basic.java:28)
Caused by: java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long
at com.mysql.jdbc.ConnectionImpl.buildCollationMapping(ConnectionImpl.java:1007)
... 15 more
BUILD SUCCESSFUL (total time: 0 seconds)
How can I solve this?
Your error clearly says casting is not possible, because a java.math.BigInteger class instance is not an instance of java.lang.Long class.
Now the question arises who is doing casting at what level, when we ask the JDBC driver to make a connection, it is doing lot of work behind the scene before it actually give us back the proper working object of connection.
The problem seems with your version of MySQL in combination with your version of mysql-connector.jar. Try a newer version of MySQL Connector/J (see https://dev.mysql.com/downloads/connector/j/ for the latest version), for example upgrade to 5.1.47 or 8.0.12 if you are using an older version.
This issue is not there with 5.1.45 as mentioned in the above comments. Available to download at,
https://repo1.maven.org/maven2/mysql/mysql-connector-java/5.1.45/
Another way, because changing the version from mysql does not worked for me, for help another people:
Long.parseLong(String.valueOf(item[0]);
There is a miss-match between your MySQL version, which might be the latest 8.0.19, but the MySQL driver file is older version may be 5.1.23, which is generally available with the NetBeans IDE. To overcome this, download the mysql-connector-java-5.1.48.jar from this link in your PC download connector/j 5.1.48 zip file
(4.6MB)
Now right-click on project name in the netbeans IDE, go to services, in that choose 'Libraries', in it choose 'Add library', then don't opt for available libraries( the drop-down menu will list a JDBCDriver file which has 'mysql-connector-java-5.1.23.jar' file inside it, which is an older version, this is causing the miss-match). Therefore, instead click on 'Create Library', now give it any name of your choice, then click the create button, a browse window will pop-up, go to the directory where you have downloaded the 'mysql-connector-java-5.1.48.zip' folder, open it and select the java jar file 'mysql-connector-java-5.1.48.jar' and click 'ok'. The library folder of your project tree will now show 'JDBCDriver-mysql-connector-java-5.1.48.jar' added in the list of libraries(JDK and Tomcat) . Now try connecting to your database again by clicking on the 'run' button, go to the JSP link, and you see that this time you are connected.
For me updating the connector wasn't enough, I also had to complete my DriverManager.getConnection() url parameter with all the arguments, even if the error message was not mentionning this issue.
In my case this parameters were needed :
"jdbc:mysql://127.0.0.1:3306/database?zeroDateTimeBehavior=convertToNull&serverTimezone=UTC"
Connector : mysql-connector-java-8.0.17.jar
mysql version : 8.0.17
Using java on netbeans.
This is a common issue when you use outdated/unsupported mysql connector driver. If youre using x86 version of Netbeans, your driver will usually be found in the Program(x86) folder an not the Program folder. something like this "C:\Program Files (x86)\MySQL\Connector J 8.0\mysql-connector-java-8.0.23.jar"
My KeyCloak works with h2 db(default) and has some data in it
i want to export the data so i can migrate KeyCloak to mysql
KeyCloak i'm using is 2.3 version
I keep getting the NPE when trying to export the data.
Command that i'm using for exporting is:
sudo ./standalone.sh -Dkeycloak.migration.action=export -Dkeycloak.migration.provider=singleFile -Dkeycloak.migration.file=/tmp/export.json
Stacktrace:
Caused by: java.lang.NullPointerException
at org.keycloak.exportimport.util.ExportUtils.exportRealm(ExportUtils.java:227)
at org.keycloak.exportimport.singlefile.SingleFileExportProvider$1.runExportImportTask(SingleFileExportProvider.java:65)
at org.keycloak.exportimport.util.ExportImportSessionTask.run(ExportImportSessionTask.java:35)
at org.keycloak.models.utils.KeycloakModelUtils.runJobInTransaction(KeycloakModelUtils.java:235)
at org.keycloak.exportimport.singlefile.SingleFileExportProvider.exportModel(SingleFileExportProvider.java:58)
at org.keycloak.exportimport.ExportImportManager.runExport(ExportImportManager.java:102)
at org.keycloak.services.resources.KeycloakApplication.<init>(KeycloakApplication.java:148)
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:423)
at org.jboss.resteasy.core.ConstructorInjectorImpl.construct(ConstructorInjectorImpl.java:150)
... 19 more
Solved this by reading H2 and creating sql script for generating tables + data
I'm not sure if this is the same issue but I was also getting a Null pointer error when trying to do a default export.
The issue for me was due to not setting the alias for an execution in the authentication flow.
https://issues.jboss.org/browse/KEYCLOAK-2494
Basically to maintain ordering of the exported Json files and keep them versionable keycloak is requiring an alias be set so that it can always do consistent sorting.
https://github.com/keycloak/keycloak/commit/c81d0c0898d7b44c0d053ce6666acdad4967bffc
The fix for me was to set an alias field in the config for the execution through the admin console, annoyingly if you've done any configuration before it won't let you update the alias. You'll have to just delete the execution in the admin console and recreate it.
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).
I'm trying to do the project explained enter link description here(the code is at the end of the page), but when I run it is risen the error:
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: SELECT command denied to user 'sqluser'#'localhost' for table 'COMMENTS'
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.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4237)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4169)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2617)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2778)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2819)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2768)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1612)
at de.vogella.mysql.first.MySQLAccess.readDataBase(MySQLAccess.java:30)
at de.vogella.mysql.first.Main.main(Main.java:7)
I think that the error could be related at the CLASSPATH but I'm not sure at all. What could be the cause of this error and how could I solve it?
The root cause of this error is quite plainly explained :
SELECT command denied to user 'sqluser'#'localhost' for table 'COMMENTS'
Just be sure to create a mysql user named sqluser and grant it the appropriate rights on the 'COMMENTS' table.
Quick and dirty : GRANT ALL PRIVILEGES ON your_db_name.* TO 'sqluser'#localhost IDENTIFIED BY 'sqluserpw';