views:

54

answers:

1

I am developing swing based application with hibernate in java . And ı want to make search on database , and listing result...

Before ı used to JDBC and ResultSetTableModel , and my before code is here :

try{

    Class.forName("*****************").newInstance();

    Connection baglan=(Connection) DriverManager.getConnection("***************","root","******");

    String sql="select * from cardtable ";

    Statement stmt=(Statement) baglan.createStatement();

    ResultSet results=(ResultSet) stmt.executeQuery(sql);

    ResultSetTableModel model=new ResultSetTableModel(results);

   jTable1.setModel(model);

        }

        catch(Exception hata)

        {

            System.out.println("here"+hata.getMessage());
        }


    }

and now my sample code is here for saving database with hibernate database operating :

 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { 

 int idd=Integer.parseInt(jTextField1.getText()); 

 String name=jTextField2.getText(); 

 String description=jTextField3.getText(); 

 Session session = null; 

 SessionFactory sessionFactory = new Configuration().configure() 
    .buildSessionFactory(); 

 session = sessionFactory.openSession(); 

 Transaction transaction = session.getTransaction(); 

   try { 


       ContactGroup con = new ContactGroup(); 

       con.setId(idd); 

       con.setGroupName(name); 
       con.setGroupDescription(description); 



       transaction.begin();  
       session.save(con);  
       transaction.commit();  


      } catch (Exception e) { 
       e.printStackTrace(); 
      } 

      finally{ 
       session.close();  
      }     
}

Now how ı can do that ?

+1  A: 

I'm not sure to understand what you're trying to do exactly: the first code snippet retrieves all the records from a table - I don't see any search feature there - and the second snippet creates a new entity - again, there is nothing approaching a search feature there.

If what you want is to make your entities searchable, I'd suggest to check and to use Hibernate Search. If this is not what you're looking for, please clarify the question.

Pascal Thivent