Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to find best query, but am getting an exception all the time.

That is my native SQL code with hibernate:

String query_string = "SELECT g.id AS id, g.createDate AS createDate,g.name AS name, g.serial AS serial, MAX(g.count) AS count, MAX(g.serviceCount) AS serviceCount, g.reportCardNo as reportCardNo " +
                      "FROM GameTransaction g" +
                      "WHERE DATE_FORMAT(createDate,'%Y-%m-%d %H:%i') BETWEEN '" + simple_date_format.format(begin_date) + " 00:00' AND '" + simple_date_format.format(end_date) + " 23:59'" +
                      "GROUP BY g.createDate, g.serial " +
                      "ORDER BY g.createDate DESC";

Query query = session.createSQLQuery(query_string)
            .addScalar("count", new IntegerType())
            .addScalar("createDate",new TimestampType())
            .addScalar("serial", new StringType())
            .addScalar("serviceCount", new IntegerType())
            .addScalar("reportCardNo", new StringType())
            .addScalar("name", new StringType())
            .addScalar("id", new LongType())
            .setResultTransformer(Transformers.aliasToBean(GameTransaction.class));

List<GameTransaction> pts = query.list();

And I am taking this exception:

"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 'DATE_FORMAT(createDate,'%Y-%m-%d %H:%i') BETWEEN '2014-10-14 00:00' AND '2014-10' at line 1"

When I change the SQL code exception changes as well For example:

"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 'BY g.createDate, g.serial ORDER BY g.createDate DESC' at line 1"

share|improve this question

put on hold as off-topic by TylerH, bummi, jpw, Nishanthi Grashia, Shankar Damodaran 3 hours ago

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – bummi, jpw, Nishanthi Grashia
If this question can be reworded to fit the rules in the help center, please edit the question.

    
BETWEEN '2014-10-14 00:00' AND '2014-10' is this a typo ? should be BETWEEN '2014-10-14 00:00' AND '2014-10-14 23:00' –  PeterMmm 17 hours ago
    
Thank you but i found answer i forgot to add space in the query thus throws the exception. –  Ertugrul 17 hours ago

Browse other questions tagged or ask your own question.