• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

SQL Syntax error within Eclipse

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys, so I'm trying to connect mysql to java eclipse for the first time, but I'm running into an error I can't figure out. I already have the table created in mysql and I am trying to insert a value into it. I'm getting an error for my mysql syntax, but I'm unsure of what the error is.





The error I receive is


 
Marshal
Posts: 3838
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My experience with MySQL is rather limited, but I'd quess that you're missing a dot between `userdatabase` and `user`.

(Assuming that userdatabase is a schema and user is a table.)
 
Taylor Manley
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're right the dot was missing, but its still throwing an error. userdatabase is a schema and user is the table.
 
Martin Vashko
Marshal
Posts: 3838
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Taylor Manley wrote:You're right the dot was missing, but its still throwing an error.


The same error or a different one?
 
Bartender
Posts: 1208
38
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whenever possible, it's better avoid using column names that are likely to be reserved words for a given DBMS. I'm afraid that your problem may be related with column 'user'.
 
Master Rancher
Posts: 4371
47
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My top tip is, run your SQL directly against the database using whatever tool makes that easier (some form of SQL GUI).
There's no point trying to cobble together SQL inside your code without actually testing whether that SQL works.
You will make mistakes (typos at a minimum) that will be a pain to figure out if you do that.

So construct and test the SQL away from Java, and then copy/paste it into your code.
 
Martin Vashko
Marshal
Posts: 3838
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What Dave says is a really good idea.

However, keep in mind that there can be differences between what can be run in an SQL client and what can be run from JDBC. I'm not sure about MySQL, but some databases/JDBC drivers don't expect the SQL statement to be ended by a semicolon, unlike an SQL client. It is possible that your current problem is the semicolon at the end of the statement.
 
Marshal
Posts: 14530
242
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
+1 to Dave's advice. Make sure you copy exactly what you tried in Java though. Looks like you're using backticks instead of single quotes there. There is a difference.
 
Martin Vashko
Marshal
Posts: 3838
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Junilu Lacar wrote:Looks like you're using backticks instead of single quotes there. There is a difference.


Backtick is the correct escape character to use with MySQL, see https://dev.mysql.com/doc/refman/5.5/en/identifiers.html
 
Junilu Lacar
Marshal
Posts: 14530
242
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see. Thanks for pointing that out. Shows how much I work with MySQL...
 
Sheriff
Posts: 6456
172
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:My top tip is, run your SQL directly against the database using whatever tool makes that easier (some form of SQL GUI)...


MySQL Workbench is a good GUI client that works in Windows, Mac, and Linux.

https://dev.mysql.com/downloads/workbench/
 
I found a beautiful pie. And a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!