Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource;
import org.jooq.SQLDialect;
import org.jooq.impl.DSL;
import java.sql.SQLException;
public final class SchemaIssue
{
private SchemaIssue()
{
}
public static void main(final String[] args)
throws SQLException
{
final var dataSource = new EmbeddedConnectionPoolDataSource();
dataSource.setDatabaseName("/tmp/example0");
dataSource.setCreateDatabase("true");
dataSource.setConnectionAttributes("create=true");
final var connection = dataSource.getConnection();
connection.setAutoCommit(false);
try (var statement = connection.prepareStatement("create schema core")) {
statement.execute();
}
try (var statement = connection.prepareStatement("create table core.example (x int)")) {
statement.execute();
}
try (var statement = connection.prepareStatement("insert into core.example values (23)")) {
statement.execute();
}
try (var statement = connection.prepareStatement("insert into core.example values (24)")) {
statement.execute();
}
try (var statement = connection.prepareStatement("insert into core.example values (25)")) {
statement.execute();
}
connection.commit();
try (var statement = connection.prepareStatement("select x from core.example")) {
try (var results = statement.executeQuery()) {
while (results.next()) {
System.out.printf("raw: %d\n", Integer.valueOf(results.getInt(1)));
}
}
}
final var context = DSL.using(connection, SQLDialect.DERBY);
try (var result =
context.select(DSL.field(DSL.name("x"), Integer.class))
.from(DSL.table(DSL.name("core", "example")))
.fetchStream()
.map(record -> record.value1())
.map(x -> System.out.printf("jooq: %d\n", x))) {
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment