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 ?