Connection connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/mydb", "username", "password");
DSLContext dslContext = DSL.using(connection, SQLDialect.POSTGRES);
List<Table<?>> tables = dslContext.meta().getTables();
for (Table<?> table : tables) {
System.out.println("Table: " + table.getName());
}
Result<Record> result = dslContext.select().from(Tables.USER).fetch();
for (Record record : result) {
System.out.println("Name: " + record.get(Tables.USER.NAME));
}
dslContext.insertInto(Tables.USER)
.set(Tables.USER.NAME, "John")
.set(Tables.USER.AGE, 30)
.execute();
DSLContext transaction = dslContext.transactionContext();
transaction.transaction(configuration -> {
DSL.using(configuration)
.update(Tables.USER)
.set(Tables.USER.NAME, "Jane")
.where(Tables.USER.ID.eq(1))
.execute();
});