use of org.jooq.ResultQuery in project jOOQ by jOOQ.
the class Example_3_4_StatementsAndResults method run.
@Test
public void run() throws SQLException {
Connection connection = connection();
Tools.title("If you don't know whether a result set is produced with JDBC");
try (PreparedStatement stmt = connection.prepareStatement("SELECT FIRST_NAME FROM AUTHOR")) {
boolean moreResults = stmt.execute();
do {
if (moreResults) {
try (ResultSet rs = stmt.getResultSet()) {
while (rs.next()) {
System.out.println(rs.getString(1));
}
}
} else {
System.out.println(stmt.getUpdateCount());
}
} while ((moreResults = stmt.getMoreResults()) || stmt.getUpdateCount() != -1);
}
Tools.title("You always know whether a result set is produced with jOOQ, because of the type");
Query q1 = DSL.using(connection).query("UPDATE AUTHOR SET LAST_NAME = LAST_NAME");
System.out.println(q1.execute());
ResultQuery<Record> q2 = DSL.using(connection).resultQuery("SELECT * FROM AUTHOR");
System.out.println(q2.fetch());
}
Aggregations