use of java.sql.PreparedStatement in project sharding-jdbc by dangdangdotcom.
the class RoutingDatabaseOnlyWithHintForDMLTest method assertUpdateWithoutAlias.
@Test
public void assertUpdateWithoutAlias() throws SQLException, DatabaseUnitException {
String sql = "UPDATE `t_order` SET `status` = ? WHERE `order_id` = ? AND `user_id` = ?";
for (int i = 10; i < 30; i++) {
for (int j = 0; j < 2; j++) {
try (DynamicShardingValueHelper helper = new DynamicDatabaseShardingValueHelper(i);
Connection connection = shardingDataSource.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
preparedStatement.setString(1, "updated");
preparedStatement.setInt(2, i * 100 + j);
preparedStatement.setInt(3, i);
assertThat(preparedStatement.executeUpdate(), is(1));
}
}
}
assertDataSet("update", "updated");
}
use of java.sql.PreparedStatement in project sharding-jdbc by dangdangdotcom.
the class RoutingDatabaseOnlyWithHintForDMLTest method assertUpdateWithAlias.
@Test
public void assertUpdateWithAlias() throws SQLException, DatabaseUnitException {
String sql = "UPDATE `t_order` AS o SET o.`status` = ? WHERE o.`order_id` = ? AND o.`user_id` = ?";
for (int i = 10; i < 30; i++) {
for (int j = 0; j < 2; j++) {
try (DynamicShardingValueHelper helper = new DynamicDatabaseShardingValueHelper(i);
Connection connection = shardingDataSource.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
preparedStatement.setString(1, "updated");
preparedStatement.setInt(2, i * 100 + j);
preparedStatement.setInt(3, i);
assertThat(preparedStatement.executeUpdate(), is(1));
}
}
}
assertDataSet("update", "updated");
}
use of java.sql.PreparedStatement in project sharding-jdbc by dangdangdotcom.
the class ShardingDataBasesOnlyWithHintForDMLTest method assertUpdateWithoutAlias.
@Test
public void assertUpdateWithoutAlias() throws SQLException, DatabaseUnitException {
String sql = "UPDATE `t_order` SET `status` = ? WHERE `order_id` = ? AND `user_id` = ?";
for (int i = 10; i < 30; i++) {
for (int j = 0; j < 2; j++) {
try (DynamicShardingValueHelper helper = new DynamicShardingValueHelper(i, i * 100 + j);
Connection connection = shardingDataSource.getConnection()) {
PreparedStatement preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, "updated");
preparedStatement.setInt(2, i * 100 + j);
preparedStatement.setInt(3, i);
assertThat(preparedStatement.executeUpdate(), is(1));
}
}
}
assertDataSet("update", "updated");
}
use of java.sql.PreparedStatement in project sharding-jdbc by dangdangdotcom.
the class ShardingDataBasesOnlyWithHintForDMLTest method assertInsertWithAllPlaceholders.
@Test
public void assertInsertWithAllPlaceholders() throws SQLException, DatabaseUnitException {
String sql = "INSERT INTO `t_order` VALUES (?, ?, ?)";
for (int i = 1; i <= 10; i++) {
try (DynamicShardingValueHelper helper = new DynamicShardingValueHelper(i, i);
Connection connection = shardingDataSource.getConnection()) {
PreparedStatement preparedStatement = connection.prepareStatement(sql);
preparedStatement.setInt(1, i);
preparedStatement.setInt(2, i);
preparedStatement.setString(3, "insert");
preparedStatement.executeUpdate();
}
}
assertDataSet("insert", "insert");
}
use of java.sql.PreparedStatement in project sharding-jdbc by dangdangdotcom.
the class ShardingDataBasesOnlyWithHintForDMLTest method assertInsertWithoutPlaceholder.
@Test
public void assertInsertWithoutPlaceholder() throws SQLException, DatabaseUnitException {
String sql = "INSERT INTO `t_order` VALUES (%s, %s, 'insert')";
for (int i = 1; i <= 10; i++) {
try (DynamicShardingValueHelper helper = new DynamicShardingValueHelper(i, i);
Connection connection = shardingDataSource.getConnection()) {
PreparedStatement preparedStatement = connection.prepareStatement(String.format(sql, i, i));
preparedStatement.executeUpdate();
}
}
assertDataSet("insert", "insert");
}
Aggregations