You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2019/12/11 07:55:39 UTC

[GitHub] [incubator-shardingsphere] GungnirLaevatain opened a new issue #3716: Can not use MySQL function named STR_TO_DATE for insert statements

GungnirLaevatain opened a new issue #3716: Can not use MySQL function named STR_TO_DATE  for insert statements
URL: https://github.com/apache/incubator-shardingsphere/issues/3716
 
 
   ## Bug Report
   
   ### Which version of ShardingSphere did you use?
   4.0.0-RC3
   ### Which project did you use? Sharding-JDBC or Sharding-Proxy?
   Sharding-JDBC
   ### Expected behavior
   execute SQL successfully
   ### Actual behavior
   ```
   Error updating database.  Cause: java.sql.SQLException: No value specified for parameter 2
   ```
   ### Example codes.
   mybatis mapper:
   ```
   <insert id="test">
       insert into test (`date`, `value` ) values (STR_TO_DATE(#{date},'%Y-%m-%d'),#{value})
   </insert>
   ```
   dao:
   ```
   public interface MapperTest{
   int test(@Param("date")String date,@Param("value")String value);
   }
   ```
   test:
   ```
   @RunWith(SpringJUnit4ClassRunner.class)
   @SpringBootTest(classes = TestApplication.class)
   public class MapperTest {
   
       @Autowired
       private MapperTest mapperTest;
   
       @Test
       public void test(){
           mapperTest.test("2017-01-06","test");
       }
   }
   ```
   result log:
   ```
   2019-12-11 15:37:24,521  INFO  50931 --- [           main] ShardingSphere-SQL                         99: [] Rule Type: sharding
   2019-12-11 15:37:24,521  INFO  50931 --- [           main] ShardingSphere-SQL                         99: [] Logic SQL: insert into test    (    `date`,    `value`    )    values (STR_TO_DATE(?,'%Y-%m-%d'),?    )
   2019-12-11 15:37:24,521  INFO  50931 --- [           main] ShardingSphere-SQL                         99: [] SQLStatement: InsertSQLStatementContext(super=CommonSQLStatementContext(sqlStatement=org.apache.shardingsphere.core.parse.sql.statement.dml.InsertStatement@3741a170, tablesContext=TablesContext(tables=[Table(name=test, alias=Optional.absent())], schema=Optional.absent())), columnNames=[date, value], insertValueContexts=[InsertValueContext(parametersCount=1, valueExpressions=[CommonExpressionSegment(startIndex=65, stopIndex=89, text=STR_TO_DATE(?,'%Y-%m-%d')), ParameterMarkerExpressionSegment(startIndex=91, stopIndex=91, parameterMarkerIndex=1)], parameters=[2017-01-06])])
   2019-12-11 15:37:24,521  INFO  50931 --- [           main] ShardingSphere-SQL                         99: [] Actual SQL: testDataSource ::: insert into test    (    `date`,    `value`    )    values (STR_TO_DATE(?,'%Y-%m-%d'), ?) ::: [2017-01-06]
   2019-12-11 15:37:24,562 ERROR  50972 --- [           main] druid.sql.Statement                       149: [] {conn-10020, pstmt-20000} execute error. insert into test    (    `date`,    `value`    )    values (STR_TO_DATE(?,'%Y-%m-%d'), ?)
   java.sql.SQLException: No value specified for parameter 2
   	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:963)
   	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:896)
   	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:885)
   	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)
   	at com.mysql.jdbc.PreparedStatement.checkAllParametersSet(PreparedStatement.java:2205)
   	at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2185)
   	at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2115)
   	at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1158)
   	at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3409)
   	at com.alibaba.druid.filter.FilterEventAdapter.preparedStatement_execute(FilterEventAdapter.java:440)
   	at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3407)
   	at com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl.execute(PreparedStatementProxyImpl.java:167)
   	at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:497)
   	at org.apache.shardingsphere.shardingjdbc.executor.SQLExecuteCallbackFactory$2.executeSQL(SQLExecuteCallbackFactory.java:65)
   	at org.apache.shardingsphere.shardingjdbc.executor.SQLExecuteCallbackFactory$2.executeSQL(SQLExecuteCallbackFactory.java:61)
   	at org.apache.shardingsphere.core.execute.sql.execute.SQLExecuteCallback.execute0(SQLExecuteCallback.java:68)
   	at org.apache.shardingsphere.core.execute.sql.execute.SQLExecuteCallback.execute(SQLExecuteCallback.java:57)
   	at org.apache.shardingsphere.core.execute.ShardingExecuteEngine.syncGroupExecute(ShardingExecuteEngine.java:125)
   	at org.apache.shardingsphere.core.execute.ShardingExecuteEngine.parallelExecute(ShardingExecuteEngine.java:102)
   	at org.apache.shardingsphere.core.execute.ShardingExecuteEngine.groupExecute(ShardingExecuteEngine.java:83)
   	at org.apache.shardingsphere.core.execute.sql.execute.SQLExecuteTemplate.executeGroup(SQLExecuteTemplate.java:73)
   	at org.apache.shardingsphere.core.execute.sql.execute.SQLExecuteTemplate.executeGroup(SQLExecuteTemplate.java:56)
   	at org.apache.shardingsphere.shardingjdbc.executor.AbstractStatementExecutor.executeCallback(AbstractStatementExecutor.java:134)
   	at org.apache.shardingsphere.shardingjdbc.executor.PreparedStatementExecutor.execute(PreparedStatementExecutor.java:158)
   	at org.apache.shardingsphere.shardingjdbc.jdbc.core.statement.ShardingPreparedStatement.execute(ShardingPreparedStatement.java:165)
   	at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:47)
   	at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74)
   	at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:50)
   	at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)
   	at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)
   	at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:197)
   	at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:184)
   	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:498)
   	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433)
   	at com.sun.proxy.$Proxy114.insert(Unknown Source)
   	at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:278)
   	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:62)
   	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:58)
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services