0

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?

giacomotb
  • 607
  • 4
  • 10
  • 24

1 Answers1

0

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';

laruiss
  • 3,780
  • 1
  • 18
  • 29
  • I've gave all the rights to that user, but now the error says `Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'FEEDBACK.COMMENTS' doesn't exist` and it was unpredictable because 1-the table exists(checked on phpmyadmin), and 2- it should exists because I followed all the step in the guide. Is that problem related to the first one? – giacomotb Dec 10 '13 at 14:02
  • No, it is not related. In PHPMyAdmin, execute this command: `show databases;` and make sure you have the FEEDBACK database, and if yes, `use FEEDBACK; show tables;` and make sure the `COMMENTS` table is listed – laruiss Dec 10 '13 at 16:31
  • yes they are. The curios part is that first the program runs an outputs data from that database, and then it raises the error. Here a part of an output: `User: lars Website: http://www.vogella.com Summary: Summary Date: 2009-09-14 Comment: My first comment Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'FEEDBACK.COMMENTS' doesn't exist` – giacomotb Dec 10 '13 at 18:55