Search in sources :

Example 31 with ResultSet

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));
    }
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Test(org.junit.Test) AbstractShardingDataBasesOnlyDBUnitTest(com.dangdang.ddframe.rdb.integrate.db.AbstractShardingDataBasesOnlyDBUnitTest)

Example 32 with ResultSet

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));
    }
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Test(org.junit.Test) AbstractShardingDataBasesOnlyDBUnitTest(com.dangdang.ddframe.rdb.integrate.db.AbstractShardingDataBasesOnlyDBUnitTest)

Example 33 with ResultSet

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));
    }
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Test(org.junit.Test) AbstractShardingDataBasesOnlyDBUnitTest(com.dangdang.ddframe.rdb.integrate.db.AbstractShardingDataBasesOnlyDBUnitTest)

Example 34 with ResultSet

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));
    }
}
Also used : Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) Test(org.junit.Test) AbstractShardingDataBasesOnlyDBUnitTest(com.dangdang.ddframe.rdb.integrate.db.AbstractShardingDataBasesOnlyDBUnitTest)

Example 35 with ResultSet

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));
    }
}
Also used : Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) Test(org.junit.Test) AbstractShardingDataBasesOnlyDBUnitTest(com.dangdang.ddframe.rdb.integrate.db.AbstractShardingDataBasesOnlyDBUnitTest)

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