MySQL Forums
Forum List  »  Newbie

Problem with query string
Posted by: Fred Whitman
Date: May 12, 2017 12:41PM

I am working on a Javafx application and I am getting an error when I query my database.

Here is my query string:
String sql = "SELECT SUM(PressCounter) AS TotalMolded, SUM(Rejects) AS TotalRejects, MONTH(ProductionDate) AS dMonth, ProductID"
+ "FROM productionlogs "
+ "WHERE ProductID = '" + productID+ "' AND YEAR(ProductionDate) = '"+ year +"'"
+ " GROUP BY MONTH(ProductionDate), ProductID";

When I use this same string in SQL Manager for Mysql it works exactly as it should, but when I run my java app I get the following error:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'WHERE ProductID = '10601' AND YEAR(ProductionDate) = '2016' GROUP BY MONTH(Prod' at line 1

Options: ReplyQuote


Subject
Written By
Posted
Problem with query string
May 12, 2017 12:41PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.