2

I am playing with some jooq code. I noticed to create sql using jooq it forces you to create a database connection. Wanted to know how to do this without a database connection:

String url = env.getProperty("spring.datasource.url");
String user = env.getProperty("spring.datasource.username");
String pass = env.getProperty("spring.datasource.password");

try (Connection conn = DriverManager.getConnection(url, user, pass)) {
    DSLContext create = DSL.using(conn, SQLDialect.SQLSERVER2014);
    String sql = create.select().from(DATA1).offset(100).limit(20).getSQL();
}
catch (Exception e) {
    e.printStackTrace();
}
1
  • No idea what you're doing but you could fire up h2 database embedded within your jvm Commented Mar 17, 2018 at 17:26

1 Answer 1

7

Just don't pass any connection to the using() call:

DSLContext create = DSL.using(SQLDialect.SQLSERVER2014);
String sql = create.select().from(DATA1).offset(100).limit(20).getSQL();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.