我正在尝试解释enter link description here项目(代码位于页面末尾),但是当我运行它时会出现错误:
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)
我认为错误可能与CLASSPATH有关,但我根本不确定。可能是造成这个错误的原因是什么,我该如何解决?
答案 0 :(得分:0)
很明显地解释了这个错误的根本原因:
SELECT command denied to user 'sqluser'@'localhost' for table 'COMMENTS'
请务必创建一个名为sqluser
的mysql用户,并在'COMMENTS'
表上授予其相应的权限。
快速而肮脏:GRANT ALL PRIVILEGES ON your_db_name.* TO 'sqluser'@localhost IDENTIFIED BY 'sqluserpw';