Does exists a java library that can create sql statements?
I’m not in search of something fancy, just something at “string manipulation” level: I just use jdbc (with Preparestatements and Resultsets) but I don’t really like to pass huge strings containing SQL code…
What I need is a “simple” Select class (or something similar); in my mind all I really want is to be able to do
SQLStatement stat = Select("*").from("table").where("condition and condition").orderby("something");
ResultSet rs = Connection.getResultSet(stat.toString());
/* equals to "select * from table where condition and condition order by something" */
Maybe I’m blind, but I cannot find something like that…
Obviously, I want some methods/class able to write inserts and updates and the other stuff…
I excluded ORMs for two reasons:
- the db schema it’s “old” and I cannot change it, and I’m not sure how can I adapt the ORM to follow our db
- AFAIK the ORMs needs to change the model (maybe adding a base class, maybe you need to implements an interface) and the model in my project is big, old and grumpy
- Onestly, I don’t really like ORMs: Objects and Set theory just aren’t made to be mapped (IMHO)
ORM (Object Relational Mapping) library is the clue.
Hibernate is the most mature one.
And the Hibernate-s Criteria API is object – oriented way to create such queries as You wished. Criteria API doc.