-->
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.  [ 13 posts ] 
Author Message
 Post subject: SQL Error: 1064, SQLState: 42000
PostPosted: Thu Aug 04, 2005 11:33 am 
Beginner
Beginner

Joined: Fri Jun 10, 2005 11:51 pm
Posts: 45
Anyone can help me with this erro:

164594 [http-8070-Processor73] INFO Add Order - addOrders()
164610 [http-8070-Processor73] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 1064, SQLState: 42000
164610 [http-8070-Processor73] ERROR org.hibernate.util.JDBCExceptionReporter - You have an error in your SQL syntax near 'order' at line 1

im using MySQL 3.28.53 and hibernate 3..what shoild i do on order to save in MySQL..tnx a lot


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 04, 2005 11:42 am 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
Post your mappings, your POJOs, your code and the SQL output (show_sql true in your hibernate.properties resp. hibernate.cfg.xml).

Best regards
Sven


Top
 Profile  
 
 Post subject: my POJO,MAppings
PostPosted: Thu Aug 04, 2005 11:47 am 
Beginner
Beginner

Joined: Fri Jun 10, 2005 11:51 pm
Posts: 45
my POJO
public class Order {
private int orderNum;
private String buyer;
private String orderDate;
private int itemId;

public String getBuyer() {
return buyer;

public int getItemId() {
return itemId;
}

public String getOrderDate() {
return orderDate;
}

public int getOrderNum() {
return orderNum;
}

public void setBuyer(String buyer) {
this.buyer = buyer;
}

public void setItemId(int itemId) {
this.itemId = itemId;
}

public void setOrderDate(String orderDate) {
this.orderDate = orderDate;
}

public void setOrderNum(int orderNum) {
this.orderNum = orderNum;
}
}

my Mapping

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<!-- < ! DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/hibernate-mapping-3.0.dtd//EN"
"http://localhost/hibernate-mapping-3.0.dtd" > -->

<hibernate-mapping package="spider">
<class name="Order" table="order">
<id column="Id" name="orderNum" type="java.lang.Integer">
<generator class="increment"/>
</id>

<property column="OrderDate" name="orderDate" type="java.lang.String"/>
<property column="ItemId" name="itemId" type="java.lang.Integer"/>
<property column="Buyer" name="buyer" type="java.lang.String"/>

</class>
</hibernate-mapping>

my cfg.xml file:

<?xml version='1.0' encoding='UTF-8'?>

<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<!-- < ! DOCTYPE hibernate-configuration "-//Hibernate/hibernate-configuration-3.0.dtd//EN"
"http://localhost/hibernate-configuration-3.0.dtd" > -->

<!-- DO NOT EDIT: This is a generated file that is synchronized -->
<!-- by MyEclipse Hibernate tool integration. -->
<hibernate-configuration >

<session-factory>

<!-- properties -->

<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/estore</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.pool_size">1</property>
<property name="hibernate.show_sql">true</property>


<!-- mapping files -->


<mapping resource="spider/Accounts.hbm.xml"/>
<mapping resource="spider/Items.hbm.xml"/>
<mapping resource="spider/Order.hbm.xml"/>
<mapping resource="spider/ItemAuction.hbm.xml"/>
<mapping resource="spider/Ratings.hbm.xml"/>
<mapping resource="spider/Bid.hbm.xml"/>


</session-factory>

</hibernate-configuration>


Top
 Profile  
 
 Post subject: Re: my POJO,MAppings
PostPosted: Thu Aug 04, 2005 11:55 am 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
Please post your code and the SQL output as well.

By the way, you should change the following:
jack182 wrote:
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">


It should be:
Code:
<!DOCTYPE hibernate-configuration PUBLIC
   "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
   "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">


Best regards
Sven


Top
 Profile  
 
 Post subject: ... ok..here the codes
PostPosted: Thu Aug 04, 2005 12:02 pm 
Beginner
Beginner

Joined: Fri Jun 10, 2005 11:51 pm
Posts: 45
here is my codes in JSP page to set the order:

newOrder.setBuyer(user.getUserName());
newOrder.setOrderDate(""+year+"-"+month+"-"+day);
newOrder.setItemId(id);
fet.addOrders(newOrder);

And here is the method i use:

public void addOrders(Order fc)
{

Session session = null;
Transaction tx = null;
Logger log = Logger.getLogger("Add Order");
log.info("addOrders()");

try {

// get the session from the factory
session = HibernateSessionFactory.currentSession();
// always start a transaction before doing something
// (even reading) from the database
tx = session.beginTransaction();

// save it to the database, Hibernate returns your object
// with the primary key field updated!
//id = (Integer) session.save(honey);

session.save(fc);

// commit your transaction or nothing is wrote to the db
tx.commit();

// clean up (close the session)
session.close();

} catch (HibernateException e) {
// when an error occured, try to rollback your transaction
if (tx != null)
try {
tx.rollback();
} catch (HibernateException e1)
{
log.warn("rollback not successful");
}

//* close your session after an exception! Your session
//* is in an undefined and unstable situation so throw it away!
if (session != null)
try {
session.close();
} catch (HibernateException e2)
{
log.warn("session close not successful");
}
}
}

i just copy it from the other method that is working and wonder why that same code is not working. :(


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 04, 2005 12:08 pm 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
I'm quite sure that the error results from the reserved keyword "order".
Use another name for your table.

Best regards
Sven


Top
 Profile  
 
 Post subject: Ei thanks a lot...
PostPosted: Thu Aug 04, 2005 12:14 pm 
Beginner
Beginner

Joined: Fri Jun 10, 2005 11:51 pm
Posts: 45
i just found out that "order" is a reserved keyword...whew i almost frak out here.. :) i rename it itemorder and it worked! :)

thank a lot Sven

best regards, jack182


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 04, 2005 12:16 pm 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
By the way, you are allowed to rate posting whether they helped you or not. :)

Best regards
Sven


Top
 Profile  
 
 Post subject: ..tnx
PostPosted: Sat Aug 06, 2005 8:38 pm 
Beginner
Beginner

Joined: Fri Jun 10, 2005 11:51 pm
Posts: 45
by the way, the link on how to rate a user in this forum is not clickable....tnx a lot and im looking forward for help to me because im developing an e-commerce for our project in school :)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 07, 2005 8:05 am 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
Not clickable?
It says: "Please rate this answer to give credits to the poster! Did it solve the problem? Yes / No"

The "Yes" and "No" is clickable.

Read this for more information:
http://forum.hibernate.org/credits.html


Top
 Profile  
 
 Post subject: ...i already rate ur help to me :)
PostPosted: Sun Aug 07, 2005 8:09 pm 
Beginner
Beginner

Joined: Fri Jun 10, 2005 11:51 pm
Posts: 45
..tnx for help...anyway,can u please give a sample code that i can use to have a pagination mechanism to e-commerce site?i just this code to page my result but it has some drawbacks and not efficient..here is my code to page the result:

<%
int startRs = 0,endRs = 0,maxRs = 10,minRs,mod;
String ex1 = request.getParameter("start");
String ex2 = request.getParameter("end");
String act = request.getParameter("act");
if( ex1 == null & ex2 == null & act == null){ex1="";ex2="";act="";}
mod = aitem.size() % maxRs;

int cp = 1;
if(maxRs < aitem.size()){
for(int cout = 0 ;cout < aitem.size(); cout+=10){
%>
<a href="searchresult.jsp?start=<%= cout %>&end=<%= maxRs %>&act=yes"><%= cp %></a>
<%
cp++;
maxRs+=10;
}
}
if(act.equals("yes")){
startRs = Integer.parseInt(ex1);
endRs = Integer.parseInt(ex2);
}else{
if(maxRs > aitem.size()){
startRs = 0;
endRs = aitem.size();
}else{
startRs = 0;
endRs = maxRs;
}
}

%>
<%= aitem.size() %>&nbsp;Match found

and here to display:

for (int x= startRs; x < endRs ; x++)
{
spider.Items t = (spider.Items) aitem.get(x);

...im using hibernate3..tnx a lot.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 07, 2005 8:17 pm 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
The database should only return the number of objects you need to display. Clicking on the next page will get you the following objects.
Loading all objects from the database and control pagination afterwards is not efficient (in most cases).

There are some links which will help you:
http://www.hibernate.org/314.html
http://www.hibernate.org/248.html

Even in the documentation:
http://www.hibernate.org/hib_docs/v3/re ... pagination

You can also search the forum for further information.

Best regards
Sven


Top
 Profile  
 
 Post subject: ...tnx
PostPosted: Mon Aug 08, 2005 12:05 am 
Beginner
Beginner

Joined: Fri Jun 10, 2005 11:51 pm
Posts: 45
..tnx i will try to implement the codes found in the links you gave to me...

Best Regards,
jack182


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 13 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.