Announcement Announcement Module
Collapse
No announcement yet.
Parameter index out of range (1 > number of parameters, which is 0) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Parameter index out of range (1 > number of parameters, which is 0)

    I have a below reader config

    Code:
     <bean id="reader"
    		class="org.springframework.batch.item.database.JdbcPagingItemReader"
    		scope="step">
    		<property name="dataSource" ref="datasource" />
    	    <property name="queryProvider">
                <bean class="org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean">
                    <property name="dataSource" ref="datasource" />
                    <property name="databaseType" value="MYSQL" />
                    <property name="selectClause" value="select uid, scanid"/>
                    <property name="fromClause" value="from table_1"/>
                     <property name="whereClause" value="where uid=58099"/>
                    <property name="sortKey" value="uid" />
                </bean>
              </property>
        		<property name="rowMapper" ref="mapper"/>
    	</bean>
    its throwing exception when i try to run the test,

    PreparedStatementCallback; SQL [SELECT uid, scanid FROM table_1 WHERE uid=58099 ORDER BY uid ASC LIMIT 10]; Parameter index out of range (1 > number of parameters, which is 0).; nested exception is java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0)

    Caused by: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).




    I have the other projects for Oracle and similar config,they are all fine, This is the first time i am configuring for a MYSQL DB, so not sure what's the issue here is , appreciate any inputs here,

    -DP

  • #2
    I guess, the issue may be specific to MYSQL.
    It may be expecting you to provide place holder(?) for the parameter(uid) in order to work with MYSQL.
    Look at: MySqlPagingQueryProvider. You may get an idea of how it works with MYSQL.

    Below is the syntax if you are Ok to go with JdbcCursorItemReader.

    <bean id="abc" class="org.springframework.batch.item.database.Jdb cCursorItemReader" scope="step">
    <property name="saveState" value="false"/>
    <property name="dataSource" ref="dataSource" />
    <property name="rowMapper" ref="rowmapper" />
    <property name="fetchSize" value="100" />
    <property name="sql" value="query" />
    <property name="preparedStatementSetter">
    <bean class="org.springframework.batch.core.resource.Lis tPreparedStatementSetter">
    <property name="parameters">
    <list>
    <value>you can read the parameter from JobParameters or hard code value here</value>

    </list>
    </property>
    </bean>
    </property>
    </bean>

    Comment

    Working...
    X