use of java.sql.ResultSet in project sharding-jdbc by dangdangdotcom.
the class MergerTestUtil method mockResult.
public static ResultSet mockResult(final List<String> columnNames) throws SQLException {
ResultSet result = getResultSet(columnNames);
when(result.next()).thenReturn(true, false);
return result;
}
use of java.sql.ResultSet in project sharding-jdbc by dangdangdotcom.
the class OrderRepositoryImpl method select.
@Override
public void select() {
String sql = "SELECT i.* FROM t_order o JOIN t_order_item i ON o.order_id=i.order_id WHERE o.user_id=? AND o.order_id=?";
try (Connection conn = shardingDataSource.getConnection();
PreparedStatement preparedStatement = conn.prepareStatement(sql)) {
preparedStatement.setInt(1, 1);
preparedStatement.setInt(2, 2);
try (ResultSet rs = preparedStatement.executeQuery()) {
while (rs.next()) {
System.out.println("orderItemId:" + rs.getInt(1) + ",orderId:" + rs.getInt(2) + ",userId:" + rs.getInt(3) + ",status:" + rs.getString(4));
}
}
// CHECKSTYLE:OFF
} catch (final Exception ex) {
// CHECKSTYLE:ON
ex.printStackTrace();
}
}
use of java.sql.ResultSet in project sharding-jdbc by dangdangdotcom.
the class ResultSetAdapterTest method assertFetchDirection.
private void assertFetchDirection(final AbstractResultSetAdapter actual, final int fetchDirection) throws SQLException {
// H2数据库未实现getFetchDirection方法
assertThat(actual.getFetchDirection(), is(DatabaseType.H2 == AbstractDBUnitTest.CURRENT_DB_TYPE ? ResultSet.FETCH_FORWARD : fetchDirection));
assertThat(actual.getResultSets().size(), is(10));
for (ResultSet each : actual.getResultSets()) {
assertThat(each.getFetchDirection(), is(DatabaseType.H2 == AbstractDBUnitTest.CURRENT_DB_TYPE ? ResultSet.FETCH_FORWARD : fetchDirection));
}
}
use of java.sql.ResultSet in project sharding-jdbc by dangdangdotcom.
the class ResultSetAdapterTest method assertClose.
private void assertClose(final AbstractResultSetAdapter actual) throws SQLException {
assertTrue(actual.isClosed());
assertThat(actual.getResultSets().size(), is(10));
for (ResultSet each : actual.getResultSets()) {
assertTrue(each.isClosed());
}
}
use of java.sql.ResultSet in project sharding-jdbc by dangdangdotcom.
the class OrderByResultSetTest method assertNextForDesc.
@Test
public void assertNextForDesc() throws SQLException {
ResultSet resultSet = ResultSetFactory.getResultSet(Arrays.<ResultSet>asList(new MockResultSet<>(4, 1), new MockResultSet<>(4, 2), new MockResultSet<Integer>()), createMergeContext(OrderByType.DESC));
assertTrue(resultSet.next());
assertThat(resultSet.getInt(1), is(4));
assertTrue(resultSet.next());
assertThat(resultSet.getInt(1), is(4));
assertTrue(resultSet.next());
assertThat(resultSet.getInt(1), is(2));
assertTrue(resultSet.next());
assertThat(resultSet.getInt(1), is(1));
assertFalse(resultSet.next());
}
Aggregations