Khrystyna Makar
Khrystyna Makar

Reputation: 472

Cast query string to Query or SelectQuery object using jOOQ

I have some query string:

String queryStr = "SELECT * FROM car";

I want cast this object to SelectQuery and then use incremental query building.

How to cast String object into SelectQuery?

Upvotes: 1

Views: 960

Answers (1)

Lukas Eder
Lukas Eder

Reputation: 220762

You cannot cast a String to any Java object. You can either:

Translate the SQL string to a jOOQ query

With jOOQ's DSL API, you'd be writing something like:

DSL.using(configuration)
   .select()
   .from(CAR);

With jOOQ's Model API (i.e. to produce a SelectQuery), you'd be writing something like:

SelectQuery select = DSL.using(configuration).selectQuery();
select.addFrom(CAR);

You're looking for the latter. The two APIs are compared here, in the manual

Embed the SQL string in a jOOQ query

This is not what you're looking for, but for completeness's sake, you can also embed SQL strings directly into jOOQ objects, e.g.

ResultQuery<?> query = DSL.using(configuration).resultQuery("SELECT * FROM car");

Upvotes: 2

Related Questions