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

PreparedStatement预编译一次,多次set值多次executeUpdate数据相同 #106

Closed
xuchanggen opened this issue Jun 18, 2016 · 4 comments

Comments

@xuchanggen
Copy link

DataSource dataSource = getShardingDataSource();
String sql = "insert ignore into t_user(login_code,user_name,age,telephone,address) values(?,?,?,?,?)";
try (
Connection conn = dataSource.getConnection();
PreparedStatement ps = conn.prepareStatement(sql);){
List userList = getUserList(20);
for(User user:userList){
ps.setString(1, user.getLoginCode());
ps.setString(2, user.getUserName());
ps.setInt(3, user.getAge());
ps.setString(4, user.getTelephone());
ps.setString(5, user.getAddress());
ps.executeUpdate();
}
ps.close();
conn.close();
}

@xuchanggen
Copy link
Author

image

@xuchanggen
Copy link
Author

image

@xuchanggen
Copy link
Author

TableRule.builder("t_user").actualTables(Arrays.asList("t_user_0", "t_user_1", "t_user_2"));实际有三张表。这种情况下都往t_user_1表中写了。getShardingDataSource()换成原生的,数据不会相同。
ps = conn.prepareStatement(sql);放入for循环中正常,会正常往三张表里面写!

@hanahmily
Copy link
Contributor

合并到 #36

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

3 participants