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));
}
}
}
}
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));
}
}
}
}
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));
}
}
}
}
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));
}
}
}
}
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);
}
Aggregations