0

I'm getting this error message below when I query a CSV file (using relique CsvDriver).

java.sql.SQLException: Syntax Error. Encountered " "GROUP "" at line 1, column 105. Was expecting one of: "AND" ... "OR" ... "ORDER" ... "LIMIT" ...

Here is my code

Class.forName("org.relique.jdbc.csv.CsvDriver");

Connection conn = DriverManager.getConnection("jdbc:relique:csv:" + mgrDir);

Statement stmt = conn.createStatement();

String query = "SELECT TRASH_TYPE AS trash_type, COUNT(TRASH_TYPE) AS num FROM " + src_file + " WHERE TRASH_DATE LIKE '" + query_date + "' GROUP BY TRASH_TYPE";

ResultSet results = stmt.executeQuery(query);

which produces the following SQL statement

SELECT TRASH_TYPE AS trash_type, COUNT(TRASH_TYPE) AS num FROM trashed WHERE TRASH_DATE LIKE '1-%-2014' GROUP BY TRASH_TYPE

Finally this is the whole error message

java.sql.SQLException: Syntax Error. Encountered " <NAME> "GROUP "" at line 1, column 105.
Was expecting one of:
<EOF> 
"AND" ...
"OR" ...
"ORDER" ...
"LIMIT" ...

at org.relique.jdbc.csv.CsvStatement.executeQuery(CsvStatement.java:331)
at com.lyris.MemberGrowthReport.generateReport(MemberGrowthReport.java:347)
at com.lyris.MemberGrowthReport.requestGenerateReport(MemberGrowthReport.java:167)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
at com.sun.jersey.server.impl.model.method.dispatch.VoidVoidDispatchProvider$VoidVoidMethodInvoker._dispatch(VoidVoidDispatchProvider.java:71)
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:540)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:715)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1085)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1556)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1513)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)

Can any shed light on this issue?

JungleJap
  • 1
  • 1
  • If you take that SQL statement and run it directly on your database, does it generate the same error? – Tab Alleman Jan 14 '15 at 14:31
  • 3
    Please look into [prepared statements](http://stackoverflow.com/questions/8263371/how-prepared-statements-can-protect-from-sql-injection-attacks) instead of concatenating strings and introducing SQL injection vulnerabilities. – Mike Samuel Jan 14 '15 at 14:31
  • Does it work without WHERE clause? Does it work without GROUP BY clause? If one of them works and another doesn't you can find an error easier. – agad Jan 14 '15 at 14:43
  • It's even more strange when I remove WHERE clause. I get the following error message. java.sql.SQLException: Syntax Error. Encountered " "BY" "BY "" at line 1, column 78. Was expecting one of: "WHERE" ... "ORDER" ... "LIMIT" ... – JungleJap Jan 14 '15 at 15:07

1 Answers1

0

It seems like it's an issue with the version of csvjdbc that I used. I tried the same code with version 1.0-18 and it worked fine.

Has anyone heard of such a bug(?) in it?

JungleJap
  • 1
  • 1