-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: SQL Error: 1064, SQLState: 42000 help me
PostPosted: Tue Mar 09, 2010 3:23 am 
Newbie

Joined: Fri Mar 05, 2010 12:21 am
Posts: 5
Code:
Hibernate: select max(nile_admin_id) from nile_admin
Hibernate: insert into nile_dev.nile_admin (current_date, is_active, password, salt_string, username, nile_admin_id) values (?, ?, ?, ?, ?, ?)
12:28:54,083 WARN  [org.hibernate.util.JDBCExceptionReporter.logExceptions(JDBCExceptionReporter.java:77)] - SQL Error: 1064, SQLState: 42000
12:28:54,088 ERROR [org.hibernate.util.JDBCExceptionReporter.logExceptions(JDBCExceptionReporter.java:78)] - 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 'current_date, is_active, password, salt_string, username, nile_admin_id) values ' at line 1
12:28:54,101 ERROR [org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:301)] - Could not synchronize database state with session
org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update

what is the problem?

thanks in Advance......


Top
 Profile  
 
 Post subject: Re: SQL Error: 1064, SQLState: 42000 help me
PostPosted: Tue Mar 09, 2010 3:52 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
current_date is a reserved word in MySQL. You need to quote the column name with backticks in your mapping. If you are using annotations:

Code:
@Column(name="`current_date`")


Top
 Profile  
 
 Post subject: Re: SQL Error: 1064, SQLState: 42000 help me
PostPosted: Tue Mar 09, 2010 4:41 am 
Newbie

Joined: Fri Mar 05, 2010 12:21 am
Posts: 5
Thankx for your kind reply,nordborg.
It's working now i can insert into the database.
As you said current_date is a keyword in Mysql, and when i single quoted the keyword(current_date) it didn't work.
I changed the column name to currentDate then it worked fine.


Top
 Profile  
 
 Post subject: Re: SQL Error: 1064, SQLState: 42000 help me
PostPosted: Tue Mar 09, 2010 4:59 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
It is not a single quote (') you need to use a back-tick (`).


Top
 Profile  
 
 Post subject: Re: SQL Error: 1064, SQLState: 42000 help me
PostPosted: Wed Jul 11, 2012 2:04 am 
Newbie

Joined: Thu Mar 29, 2012 8:16 am
Posts: 5
This problem happens when we use any kind of legal word as the name of the table or column. Here, the legal word means a word which is treated by hibernate in a different manner. For instance, if you user the word 'from' as the column name, the same error will occur because the word 'from' is used in the sql (select * from tablename). I advice you to change the column names and it will be better if you remove the underscore too.
Simply, we can say a reserved keyword cannot be used as the column name or table name......
Always happy to help you, visruthcvAtgmail.com +91-9895154767

_________________
Visruth CV


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.