aspose file tools
The moose likes JDBC and the fly likes Problem with trying to Insert values into User Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "Problem with trying to Insert values into User" Watch "Problem with trying to Insert values into User" New topic
Author

Problem with trying to Insert values into User

James Dekker
Ranch Hand

Joined: Dec 09, 2006
Posts: 215
Created a SQL script, InsertUser.sql, on MySQL 5...



This is the error I receive:


/* MySQL 01:00:12 */ You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near ''id', 'emailAddress', 'lastAccessTime', 'login_name', '
password', 'registrationD' at line 3;


Any help is most appreciated...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32833
    
    4
Have you missed out VALUES?
James Dekker
Ranch Hand

Joined: Dec 09, 2006
Posts: 215
I don't understand your question... I am MySQL n00b (very sorry to say)...

Copied this script word to word, symbol by symbol out of book...

Don't you see the VALUES declaration?

Thanks for the response...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32833
    
    4
You have got VALUES in. Sorry. I looked in the wrong place. Try removing all the quote marks in the () after "into user" and before "VALUES".
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4967

That's, like, on page 196 of my book Hibernate Made Easy! My assumption is that most people that buy my technical books rarely get past the first chapter. I'm not sure if anyone has ever read that far?

I'm wondering if the formatting for the book may be chocking MySQL. Maybe the carriage return added after or before 'VALUES' throws off the editor?

I just saw the message, so I'll be testing it.

Heh...

(1,'mj@mcnz.com','2008-01-13 14:49:01','mj','abc123','2006-02-01', 0x00),


That was written over a year ago, but still topical today. Michael Jackson never gets old.

-Cameron McKenzie


Author of Hibernate Made Easy, What is WebSphere???, JSF 2.0 Made Easy and the SCJA Certification Guides
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4967

So, that SQL was what Hibernate output to the console after running the Java code given for creating Users. It looks like you need to strip a few single quotes out of there to get it to run in the MySQL editor. Here's a single line that can be put into the MySQL query window and work as is:



The carriage returns have no harming effect. Notice the first brackets () have no single quotes around id, emailAddress, etc. I also preceeded User with examscam, and took the quotes off of user. Some databases need quotes around user as it is a reserved word for most databases.

Here's the full code I used in the MySQL query browser to get things working:



The option used in the book was to just type the following into your Java editor and run it, which is the approach I'm assuming most people used. I updated the errata page on my website:





Hibernate Made Easy Book Errata

And here's the source code if anyone is looking for it:

Source code from the book Hibernate Made Easy

Thanks for the Monday Morning assignment!

-Cameron McKenzie

 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Problem with trying to Insert values into User
 
Similar Threads
struts2.0 application issues
SSL error
Hibernate code not working on Linux Server
webservice Https connection
Query problem with MySQL 5