Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mybatis使用sjdbc做读写分离时报错(仅仅做读写分离,不做分片) #362

Closed
wangqingchengsg opened this issue Sep 6, 2017 · 1 comment

Comments

@wangqingchengsg
Copy link

使用 1.5.3版本

预期行为:插入无报错

实际行为:插入报错

步骤:

1.报错时的配置:

  <bean id="ds_0" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://localhost:3306/ds_0"/>
    <property name="username" value="root"/>
    <property name="password" value="wqch"/>
</bean>

<bean id="ds_1" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://localhost:3306/ds_1"/>
    <property name="username" value="root"/>
    <property name="password" value="wqch"/>
</bean>

<rdb:master-slave-data-source id="shardingDataSource" master-data-source-ref="ds_0" slave-data-sources-ref="ds_1" />

<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="shardingDataSource" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />

2.具体的错误:
Exception in thread "main" org.springframework.jdbc.BadSqlGrammarException:

Error updating database. Cause: java.sql.SQLException: No value specified for parameter 1

The error may involve defaultParameterMap

The error occurred while setting parameters

SQL: INSERT INTO t_order(order_id,user_id, status) VALUES ( ?, ?, ? )

Cause: java.sql.SQLException: No value specified for parameter 1

; bad SQL grammar []; nested exception is java.sql.SQLException: No value specified for parameter 1

注:但是在执行例如查询所有,删除所有等没有传递参数的操作,程序将顺利执行

3注假如不使用读写分离,仅仅注释一下配置,不用改代码,程序将顺利执行插入操作

4.github地址 https://github.com/wangqingchengsg/sharding-jdbc-example-mybatis

@haocao haocao self-assigned this Sep 6, 2017
haocao added a commit that referenced this issue Sep 6, 2017
terrymanu added a commit that referenced this issue Sep 6, 2017
@limingwei
Copy link
Contributor

Diao,今天上午才遇到这个问题,还以为是我自己的原因,也没深究

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants