Haha TTpro
Haha TTpro

Reputation: 5546

jooq sql builder output give "?" at eq() in WHERE clause

I copy the example code here:

The whole code block look like this

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.jooq.DSLContext;
import org.jooq.SQLDialect;
import static org.jooq.impl.DSL.*;


public static String sampleSql() {
    DSLContext create = DSL.using(SQLDialect.MYSQL);
    String sql = create.select(field("BOOK.TITLE"), field("AUTHOR.FIRST_NAME"), field("AUTHOR.LAST_NAME"))
            .from(table("BOOK"))
            .join(table("AUTHOR"))
            .on(field("BOOK.AUTHOR_ID").eq(field("AUTHOR.ID")))
            .where(field("BOOK.PUBLISHED_IN").eq(1948))
            .getSQL();
    return sql;
}

The output of sampleSql() is

select BOOK.TITLE, AUTHOR.FIRST_NAME, AUTHOR.LAST_NAME from BOOK join AUTHOR on BOOK.AUTHOR_ID = AUTHOR.ID where BOOK.PUBLISHED_IN = ?

But why the question mark "?", the question mark should be 1948. WHat did I miss ?

Upvotes: 2

Views: 546

Answers (1)

Simon Martinelli
Simon Martinelli

Reputation: 36103

getSQL() returns the prepared statement with ? as parameter placeholders.

If you want to inline the parameters you have to call:

getSQL(ParamType.INLINED);

Please find the API Docs here: https://www.jooq.org/javadoc/latest/org.jooq/org/jooq/Query.html

Upvotes: 3

Related Questions