Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

SQLGrammarException: could not execute query

843830Jul 17 2007
Hello,

I created a table with the script belove in a Derby database and created Entity Class for that.
create table "BAHADIR"."User"
(
	"id" NUMERIC(5) not null primary key,
	"name" VARCHAR(25),
	"email" VARCHAR(100),
	"password" VARCHAR(25),
	"role" VARCHAR(25)
)
In my controller class there's a method like that:
    public int getItemCount() {
        EntityManager em = getEntityManager();
        try{
            int count = ((Long) em.createQuery("select count(o) from User as o").getSingleResult()).intValue();
            return count;
        } finally {
            em.close();
        }
    }
When this method is called I get that exception stack:


HTTP Status 500 -

type Exception report

message

descriptionThe server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query

root cause

javax.el.ELException: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query

root cause

javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query

root cause

org.hibernate.exception.SQLGrammarException: could not execute query

root cause

java.sql.SQLSyntaxErrorException: Syntax error: Encountered "User" at line 1, column 42.

root cause

org.apache.derby.client.am.SqlException: Syntax error: Encountered "User" at line 1, column 42.

note The full stack traces of the exception and its root causes are available in the Sun Java System Application Server 9.1 logs.
Sun Java System Application Server 9.1



What does these mean? The IDE created the access method automatically, so it can not be wrong. So where's the error?

Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 14 2007
Added on Jul 17 2007
0 comments
2,270 views