use of java.sql.ResultSet in project sharding-jdbc by dangdangdotcom.
the class ShardingPreparedStatementTest method assertExecuteQueryWithResultSetHoldabilityIsZero.
@Test
public void assertExecuteQueryWithResultSetHoldabilityIsZero() throws SQLException {
String sql = "SELECT COUNT(*) AS `orders_count` FROM `t_order` WHERE `status` = ?";
try (Connection connection = shardingDataSource.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, 0)) {
preparedStatement.setString(1, "init");
ResultSet resultSet = preparedStatement.executeQuery();
assertTrue(resultSet.next());
assertThat(resultSet.getLong(1), is(40L));
}
}
use of java.sql.ResultSet in project sharding-jdbc by dangdangdotcom.
the class ShardingPreparedStatementTest method assertExecuteQueryWithColumnIndexes.
@Test
public void assertExecuteQueryWithColumnIndexes() throws SQLException {
String sql = "SELECT COUNT(*) AS `orders_count` FROM `t_order` WHERE `status` = ?";
try (Connection connection = shardingDataSource.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(sql, new int[] { 1 })) {
preparedStatement.setNull(1, java.sql.Types.VARCHAR);
ResultSet resultSet = preparedStatement.executeQuery();
assertTrue(resultSet.next());
assertThat(resultSet.getLong(1), is(0L));
}
}
use of java.sql.ResultSet in project sharding-jdbc by dangdangdotcom.
the class ShardingPreparedStatementTest method assertExecuteQueryWithParameter.
@Test
public void assertExecuteQueryWithParameter() throws SQLException {
String sql = "SELECT COUNT(*) AS `orders_count` FROM `t_order` WHERE `status` = ?";
try (Connection connection = shardingDataSource.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
preparedStatement.setString(1, "init");
ResultSet resultSet = preparedStatement.executeQuery();
assertTrue(resultSet.next());
assertThat(resultSet.getLong(1), is(40L));
preparedStatement.setString(1, "null");
resultSet = preparedStatement.executeQuery();
assertTrue(resultSet.next());
assertThat(resultSet.getLong(1), is(0L));
preparedStatement.setString(1, "init");
resultSet = preparedStatement.executeQuery();
assertTrue(resultSet.next());
assertThat(resultSet.getLong(1), is(40L));
}
}
use of java.sql.ResultSet in project sharding-jdbc by dangdangdotcom.
the class ShardingStatementTest method assertExecuteQueryWithResultSetHoldabilityIsZero.
@Test
public void assertExecuteQueryWithResultSetHoldabilityIsZero() throws SQLException {
String sql = "SELECT COUNT(*) AS `orders_count` FROM `t_order` WHERE `status` = 'init'";
try (Connection connection = shardingDataSource.getConnection();
Statement stmt = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, 0);
ResultSet resultSet = stmt.executeQuery(sql)) {
assertTrue(resultSet.next());
assertThat(resultSet.getLong(1), is(40L));
}
}
use of java.sql.ResultSet in project sharding-jdbc by dangdangdotcom.
the class ShardingStatementTest method assertExecuteQueryWithResultSetTypeAndResultSetConcurrency.
@Test
public void assertExecuteQueryWithResultSetTypeAndResultSetConcurrency() throws SQLException {
String sql = "SELECT COUNT(*) AS `orders_count` FROM `t_order` WHERE `status` = 'init'";
try (Connection connection = shardingDataSource.getConnection();
Statement stmt = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
ResultSet resultSet = stmt.executeQuery(sql)) {
assertTrue(resultSet.next());
assertThat(resultSet.getLong(1), is(40L));
}
}
Aggregations