質問編集履歴

1 タイトル修正

milkman4

milkman4 score 31

2016/03/13 17:37  投稿

syntax error at or near ":"が発生
postgresでsyntax error at or near ":"が発生
MyBatisとpostgresを使ってjavaのwebアプリケーションを作成しています。
下記のようにinsertのクエリを実行するとエラーが発生してしまいます。
■MyBatisのxmlファイル
```xml
<insert id="insertRace">
insert into t_race( race_id, obstacle_flg, race_name, grade, race_number, field_type, distance, rotate_type, weather, field_condition, host_id, post_time, host_date, host_times, host_days, horse_type, age_condition, product_condition, appointed_condition, sex_condition, weight_condition, insert_date, insert_user, update_date, update_user)
values ('${raceId}', ${obstacleFlg}, '${raceName}', '${grade}', ${raceNumber}, '${fieldType}', ${distance}, '${rotateType}', '${weather}', '${fieldCondition}', '${hostId}', ${postTime}, ${hostDate}, ${hostTimes}, ${hostDays}, ${horseType}, '${ageCondition}', ${productCondition}, ${appointedCondition}, ${sexCondition}, ${weightCondition}, CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM')
</insert>
```
■postgresで出力されるエラー
```postgreSQL
ERROR: syntax error at or near ":" at character 433
STATEMENT: insert into t_race( race_id, obstacle_flg, race_name, grade, race_number, field_type, distance, rotate_type, weather, field_condition, host_id, post_time, host_date, host_times, host_days, horse_type, age_condition, product_condition, appointed_condition, sex_condition, weight_condition, insert_date, insert_user, update_date, update_user)
values ('201606020302', 0, '3歳未勝利', '未勝利', 2, 'ダート', 1200, '右', '曇', '良', '06', 10:40:00, 2016-03-05, 2, 3, 1, '3歳', 1, 2, 999, 4, CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM')
```
■javaのコンソール例外
```java
### Error updating database. Cause: org.postgresql.util.PSQLException: ERROR: syntax error at or near ":"
ポジション: 433
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: insert into t_race( race_id, obstacle_flg, race_name, grade, race_number, field_type, distance, rotate_type, weather, field_condition, host_id, post_time, host_date, host_times, host_days, horse_type, age_condition, product_condition, appointed_condition, sex_condition, weight_condition, insert_date, insert_user, update_date, update_user) values ('201606020302', 0, '3歳未勝利', '未勝利', 2, 'ダート', 1200, '右', '曇', '良', '06', 10:40:00, 2016-03-05, 2, 3, 1, '3歳', 1, 2, 999, 4, CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM')
### Cause: org.postgresql.util.PSQLException: ERROR: syntax error at or near ":"
ポジション: 433
; bad SQL grammar []; nested exception is org.postgresql.util.PSQLException: ERROR: syntax error at or near ":"
ポジション: 433] with root cause
org.postgresql.util.PSQLException: ERROR: syntax error at or near ":"
ポジション: 433
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2102)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1835)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:500)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:388)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:381)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:45)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:73)
at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:49)
at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:115)
at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:75)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:170)
at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:157)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358)
at com.sun.proxy.$Proxy12.insert(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:240)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:52)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53)
at com.sun.proxy.$Proxy24.insertRace(Unknown Source)
at jp.keiba.analitics.service.ScrapingDataService.insertRace(ScrapingDataService.java:169)
at jp.keiba.analitics.service.ScrapingDataService.insertAll(ScrapingDataService.java:45)
at jp.keiba.analitics.controller.scraping.UrlRaceScrpController.raceComplete(UrlRaceScrpController.java:90)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:817)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:731)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:968)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:859)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:844)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
```
クエリに":"は使用しておらず、なぜエラーメッセージに「ERROR: syntax error at or near ":" 」が出力されるのか、解決方法がわからず困っております。
お手数をおかけしますがお力添えをいただけると大変幸いです。
よろしくお願いいたします。
  • PostgreSQL

    2415 questions

    PostgreSQLはオープンソースのオブジェクトリレーショナルデータベース管理システムです。 Oracle Databaseで使われるPL/SQLを参考に実装されたビルトイン言語で、Windows、 Mac、Linux、UNIX、MSなどいくつものプラットフォームに対応しています。

  • MyBatis

    117 questions

    MyBatisはJavaや.NET Frameworkでなどで使用できる、SQL文や、ストアドプロシージャをオブジェクトと紐付けるO/Rマッピングフレームワークです。

思考するエンジニアのためのQ&Aサイト「teratail」について詳しく知る