We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
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(); }
The text was updated successfully, but these errors were encountered:
Sorry, something went wrong.
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循环中正常,会正常往三张表里面写!
合并到 #36
No branches or pull requests
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();
}
The text was updated successfully, but these errors were encountered: