Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Com.mysql.jdbc.MySQLSyntaxErrorException: Table 'comments.politics_news' doesn't exist.

 
Victor Ade
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With the amount of information online about this error I bet anyone who's solved this issue on a platter of gold would say i didn't do enough research. But I did. I've dropped my database, create another in an attempt to solve this error but no it didn't work. When I create another table in 'comments' and inserted data into it it worked perfectly but when I try to insert into 'politics_news' after creating it In my java program i get this error. I get the same error when I try to insert through database client also.

Here's the block of code that throws the error:
 
Victor Ade
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Victor Ade wrote:With the amount of information online about this error I bet anyone who's solved this issue on a platter of gold would say i didn't do enough research. But I did. I've dropped my database, create another in an attempt to solve this error but no it didn't work. When I create another table in 'comments' and inserted data into it it worked perfectly but when I try to insert into 'politics_news' after creating it In my java program i get this error. I get the same error when I try to insert through database client also.

Here's the block of code that throws the error:


ERROR FREE VERSION


With the amount of information online about this error I bet anyone who's solved this issue on a platter of gold would say i didn't do enough research. But I did. I've dropped my database, create another in an attempt to solve this error but no it didn't work. When I create another table in 'comments' and inserted data into it it worked perfectly but when I try to insert into 'politics_news' after creating it In my java program i get this error. I get the same error when I try to insert through database client also.

Here's the block of code that throws the error:




 
Dave Tolls
Ranch Hand
Posts: 2369
25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Build your table creation String as a separate object and print it out.
Looks to me like there aren't enough spaces in there.
It would also help ensure the table name is valid.

Do you have an catch blocks for checking SQLExceptions?  I would have expected the CREATE TABLE to throw an error.

Also, I think that should be an executeUpdate?  Can't guarantee that part, though.
 
Knute Snortum
Sheriff
Posts: 3324
84
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Don't you need a space right after TABLE?
 
Paul Clapham
Sheriff
Posts: 21961
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code:



Won't compile. But assuming you wanted to use the setString() method, like this:



You still have a problem, namely that you never set the second and third parameters of the PreparedStatement. You should get an exception thrown in that case too -- is it possible that you have a catch block which ignores exceptions? In both cases, this one and the one where your Create Table statement is missing whitespace, you should have got an exception which described the problem for you.

 
Victor Ade
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:
Don't you need a space right after TABLE?


you are king knute. this is where the problem lies.
 
Knute Snortum
Sheriff
Posts: 3324
84
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.  Dave Tolls mentioned it too.
 
Dave Tolls
Ranch Hand
Posts: 2369
25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Victor Ade wrote:

you are king knute. this is where the problem lies.


Which should have resulted in a SQLException.
The fact that it didn't implies that you are either ignoring exceptions (empty catch blocks) or you are not logging them properly (printing the stack trace and message).

That's a bug that needs fixing, as it would have saved you a lot of time.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!