Search in sources :

Example 1 with ResultQuery

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());
}
Also used : ResultQuery(org.jooq.ResultQuery) Query(org.jooq.Query) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Record(org.jooq.Record) Test(org.junit.Test)

Aggregations

Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 Query (org.jooq.Query)1 Record (org.jooq.Record)1 ResultQuery (org.jooq.ResultQuery)1 Test (org.junit.Test)1