반응형

스프링이나 자바프로젝트에서 jdbc tempate으로 hive명령어 날릴 때 쿼리문에 ';'(세미콜론)을 붙혀 statement를 execute하지 않도록 하자. 세미콜론이 쿼리에 들어 있으면 다음과 같은 에러를 뱉을 것이다.

Caused by: org.apache.hive.service.cli.HiveSQLException: Error while compiling statement: FAILED: ParseException line 1:519 cannot recogni input near ';' '<EOF>' '<EOF>' in expression specification

        at org.apache.hive.service.cli.operation.Operation.toSQLException(Operation.java:326)

        at org.apache.hive.service.cli.operation.SQLOperation.prepare(SQLOperation.java:102)

        at org.apache.hive.service.cli.operation.SQLOperation.runInternal(SQLOperation.java:171)

        at org.apache.hive.service.cli.operation.Operation.run(Operation.java:268)

        at org.apache.hive.service.cli.session.HiveSessionImpl.executeStatementInternal(HiveSe

이유는 스택오버플로우의 답변으로 대신한다.


Using ; in a query for most databases doesn't work as it is usually not part of the statement syntax itself, but a terminator for command line or script input to separate statements. The command line or script processor sees a semi-colon as the signal that the statement is complete and can be sent to the server.
Also in JDBC a single statement prepare (or execute) should only be one actual statement so multiple statements are not allowed and so there is also no need to have a semi-colon, and as for some (most?) databases the semi-colon isn't part of the statement syntax, it is simply a syntax error to have one included.
If you want to execute multiple statements, you need to use separate executes. Technically, MySQL does have an option to support multiple executions which can be enabled by a connection property. This behavior is not compliant with the JDBC specification/API and makes your code less portable. See allowMultiQueries on Driver/Datasource Class Names, URL Syntax and Configuration Properties for Connector/J

--------

Having semicolons in JDBC statements is very error prone in general. Some JDBC drivers do not support this (e.g. IBM's JDBC driver for DB2 10.x throws an exception if you close your SQL statement with ";").

 

참고 : https://stackoverflow.com/questions/18515471/can-i-execute-multiple-queries-separated-by-semicolon-with-mysql-connector-j

반응형

+ Recent posts