views:

65

answers:

2

Hi All ; I want to make searching on my database with hibernate in Java, how can I do that?

Normally when I am using JDBC I wrote this code :

String Sql="select * from table1 where id like '"+jTextField1.getText()+"%'";

but I want to do that with hibernate database operation,

do I need to use session.load(..) ?

Thanks from now...

And can ı display results in Jtable?

+2  A: 

You can use a Hibernate Criteria Query

Criteria crit = session.createCriteria(MyBean.class);
crit.add(Restrictions.like("name", "%xyz%"));
List results = crit.list();

Or a HQL query

session.createQuery("SELECT FROM MyBean WHERE name like '%xyz%'").list();
Daff
Thanks it's work and now can ı show that results in(jTable) by help f resultsettable model?Or how can ı display result in swing based application?
ruby
+1  A: 

One way to accomplish this is to use Hibernate Criteria queries. Here's a link to a number of examples.

And, here's another.

Essentially, you'll want to create a Criteria instance using the APIs, and then add Restrictions to that Criteria.

elduff