M
M
Maxim2016-01-22 20:40:53
Java
Maxim, 2016-01-22 20:40:53

What is the best way to generate SQL?

I am looking for the most suitable tool for Java to generate SQL code (create table, selects, etc).
At the expense of Freemarker, Velocity, StringTemplates is more or less clear.
What else is more suitable for code generation?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaly Musin, 2016-01-22
@vmpartner

For SQL, I think the best client for Windows is HeidiSQL www.heidisql.com
This is an OpenSource project that is constantly developed by a huge community, updates are released 3-4 times a month.

B
bromzh, 2016-01-23
@bromzh

If you want something like this:

CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Book> q = cb.createQuery(Book.class);
Root<Book> b = q.from(Book.class);
q.select(b).orderBy(cb.desc(b.get("id")));
TypedQuery<Book> findAllBooks = em.createQuery(q);

Those. build queries programmatically, then google something like "JPA dynamic queries". See here for how to use them correctly .
And to see what your ORM provider has generated for you, then Query has an unwrap method that will return the implementation of the JPA provider to you (the most popular is hibernate). And then, you can get the generated SQL. More details here (from the words "Getting the JPQL/SQL String... .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question