Search in sources :

Example 16 with ResultSet

use of java.sql.ResultSet in project sharding-jdbc by dangdangdotcom.

the class YamlWithAssignedDataSourceMain method printSimpleSelect.

private static void printSimpleSelect(final DataSource dataSource) throws SQLException {
    String sql = "SELECT c.* FROM t_config c";
    try (Connection conn = dataSource.getConnection();
        PreparedStatement preparedStatement = conn.prepareStatement(sql)) {
        try (ResultSet rs = preparedStatement.executeQuery()) {
            while (rs.next()) {
                System.out.println(rs.getInt(1));
                System.out.println(rs.getString(2));
                System.out.println(rs.getString(3));
            }
        }
    }
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 17 with ResultSet

use of java.sql.ResultSet in project sharding-jdbc by dangdangdotcom.

the class YamlWithAssignedDataSourceMain method printJoinSelect.

private static void printJoinSelect(final DataSource dataSource) throws SQLException {
    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 = dataSource.getConnection();
        PreparedStatement preparedStatement = conn.prepareStatement(sql)) {
        preparedStatement.setInt(1, 10);
        preparedStatement.setInt(2, 1001);
        try (ResultSet rs = preparedStatement.executeQuery()) {
            while (rs.next()) {
                System.out.println(rs.getInt(1));
                System.out.println(rs.getInt(2));
                System.out.println(rs.getString(3));
            }
        }
    }
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 18 with ResultSet

use of java.sql.ResultSet in project sharding-jdbc by dangdangdotcom.

the class YamlWithDefaultDataSourceMain method printJoinSelect.

private static void printJoinSelect(final DataSource dataSource) throws SQLException {
    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 = dataSource.getConnection();
        PreparedStatement preparedStatement = conn.prepareStatement(sql)) {
        preparedStatement.setInt(1, 10);
        preparedStatement.setInt(2, 1001);
        try (ResultSet rs = preparedStatement.executeQuery()) {
            while (rs.next()) {
                System.out.println(rs.getInt(1));
                System.out.println(rs.getInt(2));
                System.out.println(rs.getString(3));
            }
        }
    }
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 19 with ResultSet

use of java.sql.ResultSet in project sharding-jdbc by dangdangdotcom.

the class Main method printHintSimpleSelect.

private static void printHintSimpleSelect(final DataSource dataSource) throws SQLException {
    String sql = "SELECT i.* FROM t_order o JOIN t_order_item i ON o.order_id=i.order_id";
    try (HintManager hintManager = HintManager.getInstance();
        Connection conn = dataSource.getConnection();
        PreparedStatement preparedStatement = conn.prepareStatement(sql)) {
        hintManager.addDatabaseShardingValue("t_order", "user_id", 10);
        hintManager.addTableShardingValue("t_order", "order_id", 1001);
        try (ResultSet rs = preparedStatement.executeQuery()) {
            while (rs.next()) {
                System.out.println(rs.getInt(1));
                System.out.println(rs.getInt(2));
                System.out.println(rs.getInt(3));
            }
        }
    }
}
Also used : HintManager(com.dangdang.ddframe.rdb.sharding.api.HintManager) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 20 with ResultSet

use of java.sql.ResultSet in project sharding-jdbc by dangdangdotcom.

the class StatementAdapterTest method assertGetGeneratedKeysForSingleRoutedStatement.

@Test
public void assertGetGeneratedKeysForSingleRoutedStatement() throws SQLException {
    actual.executeUpdate("INSERT INTO `t_order` (`user_id`, `status`) VALUES (1, 'init')");
    ResultSet generatedKeysResult = actual.getGeneratedKeys();
    assertTrue(generatedKeysResult.next());
    assertTrue(generatedKeysResult.getInt(1) > 0);
}
Also used : ResultSet(java.sql.ResultSet) AbstractDBUnitTest(com.dangdang.ddframe.rdb.integrate.AbstractDBUnitTest) 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