반응형
스프링이나 자바프로젝트에서 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 ";").
반응형
'Programming > Java,Spring' 카테고리의 다른 글
[ Springboot ] 쿠키를 response에 add해줬는데 브라우저에 안남아요??? redirect?? (3) | 2020.02.02 |
---|---|
JPA query 업데이트시 에러 QueryExecutionRequestException (0) | 2020.02.01 |
[ Spring ] URL redirect할 경우 사용하면 안되는 문자열들 (0) | 2019.11.13 |
[ Springboot / JPA ] JPA composite key 사용할 때 @IdClass, Serializable (2) | 2019.10.14 |
[ Spring ehcache ] ehcache를 사용할 때 주의할점 (proxy...) (0) | 2019.10.04 |