Search in sources :

Example 21 with ResultSet

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;
}
Also used : ResultSet(java.sql.ResultSet)

Example 22 with ResultSet

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();
    }
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 23 with ResultSet

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));
    }
}
Also used : ResultSet(java.sql.ResultSet)

Example 24 with ResultSet

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());
    }
}
Also used : ResultSet(java.sql.ResultSet)

Example 25 with ResultSet

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());
}
Also used : MockResultSet(com.dangdang.ddframe.rdb.sharding.merger.fixture.MockResultSet) ResultSet(java.sql.ResultSet) MockResultSet(com.dangdang.ddframe.rdb.sharding.merger.fixture.MockResultSet) Test(org.junit.Test)

Aggregations

ResultSet (java.sql.ResultSet)16614 PreparedStatement (java.sql.PreparedStatement)9996 SQLException (java.sql.SQLException)7083 Connection (java.sql.Connection)6929 Statement (java.sql.Statement)4787 Test (org.junit.Test)3656 ArrayList (java.util.ArrayList)2584 Properties (java.util.Properties)1232 HashMap (java.util.HashMap)681 ResultSetMetaData (java.sql.ResultSetMetaData)660 CallableStatement (java.sql.CallableStatement)580 DatabaseMetaData (java.sql.DatabaseMetaData)512 List (java.util.List)471 IOException (java.io.IOException)465 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)414 Map (java.util.Map)409 Timestamp (java.sql.Timestamp)384 BigDecimal (java.math.BigDecimal)358 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)292 HashSet (java.util.HashSet)282