From: Ken on
I just looked at hibernate... but have never used it.

Can it or any other main stream java tools query databases with an
optional WHERE clause?

What I mean is I have a number of cases where people fill in forms
with quite a few criteria and then I need to build a query. I've been
concatenating strings recently to make this work (although in my
defense I've been programing in IBM RPG, yes that language that
started on punch cards...) but I want to know how to do this
effectively in Java.

I know it is probably possible to build all the needed statements in
SQL conditional logic but I think it will make the statements far more
complicated.

I'd imagine there is a nice API for which you simply create a
statement object and then specify it's type (such as SELECT) and then
add constraints via the API and don't need to mess around doing
painful string concatenations.

I think this can be done with SQL PL? But I don't have access to SQL
PL in my environment but am hoping for some tool that can add this
functionality.

Something like:
Stmt stmt = new stmt();
Select select = new select(stmt);
select.addField("name");
select.from("people");
if (somecondition != null)
select.addWhere("x > " + somecondition);
endif;

Or perhaps there is something that even makes the above look like work
=)
From: Arne Vajhøj on
On 31-03-2010 19:27, Ken wrote:
> I just looked at hibernate... but have never used it.
>
> Can it or any other main stream java tools query databases with an
> optional WHERE clause?
>
> What I mean is I have a number of cases where people fill in forms
> with quite a few criteria and then I need to build a query. I've been
> concatenating strings recently to make this work (although in my
> defense I've been programing in IBM RPG, yes that language that
> started on punch cards...) but I want to know how to do this
> effectively in Java.
>
> I know it is probably possible to build all the needed statements in
> SQL conditional logic but I think it will make the statements far more
> complicated.
>
> I'd imagine there is a nice API for which you simply create a
> statement object and then specify it's type (such as SELECT) and then
> add constraints via the API and don't need to mess around doing
> painful string concatenations.
>
> I think this can be done with SQL PL? But I don't have access to SQL
> PL in my environment but am hoping for some tool that can add this
> functionality.
>
> Something like:
> Stmt stmt = new stmt();
> Select select = new select(stmt);
> select.addField("name");
> select.from("people");
> if (somecondition != null)
> select.addWhere("x> " + somecondition);
> endif;
>
> Or perhaps there is something that even makes the above look like work
> =)

You can build criterias in Hibernate.

http://docs.jboss.org/hibernate/core/3.3/reference/en/html/querycriteria.html

Arne

From: Ken on
On Mar 31, 5:30 pm, Arne Vajhøj <a...(a)vajhoej.dk> wrote:
> On 31-03-2010 19:27, Ken wrote:
>
>
>
> > I just looked at hibernate... but have never used it.
>
> > Can it or any other main stream java tools query databases with an
> > optional WHERE clause?
>
> > What I mean is I have a number of cases where people fill in forms
> > with quite a few criteria and then I need to build a query.  I've been
> > concatenating strings recently to make this work (although in my
> > defense I've been programing in IBM RPG, yes that language that
> > started on punch cards...) but I want to know how to do this
> > effectively in Java.
>
> > I know it is probably possible to build all the needed statements in
> > SQL conditional logic but I think it will make the statements far more
> > complicated.
>
> > I'd imagine there is a nice API for which you simply create a
> > statement object and then specify it's type (such as SELECT) and then
> > add constraints via the API and don't need to mess around doing
> > painful string concatenations.
>
> > I think this can be done with SQL PL?  But I don't have access to SQL
> > PL in my environment but am hoping for some tool that can add this
> > functionality.
>
> > Something like:
> > Stmt stmt = new stmt();
> > Select select = new select(stmt);
> > select.addField("name");
> > select.from("people");
> > if (somecondition != null)
> > select.addWhere("x>  " + somecondition);
> > endif;
>
> > Or perhaps there is something that even makes the above look like work
> > =)
>
> You can build criterias in Hibernate.
>
> http://docs.jboss.org/hibernate/core/3.3/reference/en/html/querycrite...
>
> Arne

Yes this is exactly what I was thinking! I think...
From: Arne Vajhøj on
On 31-03-2010 19:57, Ken wrote:
> On Mar 31, 5:30 pm, Arne Vajh�j<a...(a)vajhoej.dk> wrote:
>> On 31-03-2010 19:27, Ken wrote:
>>> I just looked at hibernate... but have never used it.
>>>
>>> Can it or any other main stream java tools query databases with an
>>> optional WHERE clause?
....
>> You can build criterias in Hibernate.
>>
>> http://docs.jboss.org/hibernate/core/3.3/reference/en/html/querycrite...
>
> Yes this is exactly what I was thinking! I think...

Thinking is good !

Arne

From: Lew on
Arne Vajhøj wrote:
> On 31-03-2010 19:57, Ken wrote:
>> On Mar 31, 5:30 pm, Arne Vajhøj<a...(a)vajhoej.dk> wrote:
>>> On 31-03-2010 19:27, Ken wrote:
>>>> I just looked at hibernate... but have never used it.
>>>>
>>>> Can it or any other main stream java tools query databases with an
>>>> optional WHERE clause?
> ...
>>> You can build criterias in Hibernate.
>>>
>>> http://docs.jboss.org/hibernate/core/3.3/reference/en/html/querycrite...
>>
>> Yes this is exactly what I was thinking! I think...
>
> Thinking is good !

Use the JPA packages, which Hibernate supports.

--
Lew