-->
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.  [ 1 post ] 
Author Message
 Post subject: Special Characters errors when making queries dynamically
PostPosted: Wed Jul 13, 2005 11:33 am 
Newbie

Joined: Thu Aug 26, 2004 9:25 am
Posts: 8
Hi, my problem is as follow :
I create a query dynamically, for example

String texto = "VW '97 (L/V)"
String query = "from ar.com.csi.gestioncomercial.model.Producto producto";
query = query + " where producto.description >= '"
+ texto + "'" + "ORDER BY producto.description";

Then I call the method listByCriteria(String, int), showed below, with query and 50 as parameters. When the line with qry.list() is reached then raise the exception mentioned below.
I think the problem is with the character '. I've been trying and I've got the same exception with characters as ( or ).
Could anybody give me some clue ?
Thanks in advance.

Mauro.

Hibernate version: 2.1.3

Mapping documents:

Code between sessionFactory.openSession() and session.close():

public List listByCriteria(String str, int maxResult) throws SQLException {
try {
Session session = HibernateUtil.currentSession();
Query qry = session.createQuery(str);
qry.setMaxResults(maxResult);
List resultList = qry.list();
return resultList;
} catch (Exception e){
System.out.println(
"EXCEPTION!!! on listByCriteria(str) ProductoHibernateImpl: ");
e.printStackTrace();
throw new SQLException(e.getMessage());
} finally {
HibernateUtil.closeSession();
}
}


Full stack trace of any exception that occurs:

net.sf.hibernate.JDBCException: Could not execute query

at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1539)

at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)

at ar.com.csi.encendidosur.model.dao.impl.hibernate.ProductoDAOHibernateImpl.listByCriteria(ProductoDAOHibernateImpl.java:147)

at ar.com.csi.encendidosur.controller.MainQueryController.buildProductoQuery(MainQueryController.java:378)

at ar.com.csi.encendidosur.controller.MainQueryController.doQuery(MainQueryController.java:209)

at ar.com.csi.encendidosur.controller.MainQueryController.doRefresh(MainQueryController.java:107)

at ar.com.csi.encendidosur.controller.MainQueryController.actionPerformed(MainQueryController.java:91)

at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)

at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.setPressed(Unknown Source)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)

at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)

at java.awt.Component.processMouseEvent(Unknown Source)

at java.awt.Component.processEvent(Unknown Source)

at java.awt.Container.processEvent(Unknown Source)

at java.awt.Component.dispatchEventImpl(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Window.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.run(Unknown Source)

Caused by: java.sql.SQLException: Syntax error or access violation, message from server: "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 '97 L/V ) limit 50' at line 1"

at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1905)

at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1109)

at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1203)

at com.mysql.jdbc.Connection.execSQL(Connection.java:2090)

at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1496)

at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:87)

at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:800)

at net.sf.hibernate.loader.Loader.doQuery(Loader.java:189)

at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)

at net.sf.hibernate.loader.Loader.doList(Loader.java:955)

at net.sf.hibernate.loader.Loader.list(Loader.java:946)

at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:834)

at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1536)

... 30 more


Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


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

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.