Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

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


 
Sheriff
Posts: 3837
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
Sheriff
Posts: 3837
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: 1264
39
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'.
 
Rancher
Posts: 4587
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
Sheriff
Posts: 3837
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: 15634
264
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
Sheriff
Posts: 3837
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: 15634
264
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: 7108
184
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/
 
Come have lunch with me Arthur. Adventure will follow. This tiny ad:
ScroogeXHTML 9.0 - RTF to HTML5 and XHTML converter
https://coderanch.com/t/731949/ScroogeXHTML-RTF-HTML-XHTML-converter
    Bookmark Topic Watch Topic
  • New Topic