public class TableDAOImpl implements TableDAO {
private SessionFactory sessionFactory=new Configuration()
.configure("hibernate.cfg.xml")
.buildSessionFactory();
@Override
public void save(Table table) {
// TODO Auto-generated method stub
Session session=sessionFactory.openSession();
try {
Transaction tx=session.beginTransaction();
session.save(table);
// session.getTransaction().commit();
if (!tx.wasCommitted()){
tx.commit();
}
} catch(Exception e) {
System.out.println("SAVE: "+e);
session.getTransaction().rollback();
}
session.clear();
}
@Override
public void update(Table table) {
// TODO Auto-generated method stub
Session session=sessionFactory.openSession();
try{
session.beginTransaction();
session.update(table);
session.getTransaction().commit();
} catch(Exception e) {
System.out.println("UPDATE: "+e);
session.getTransaction().rollback();
}
session.clear();
}
@Override
public void delete(Table table) {
// TODO Auto-generated method stub
Session session=sessionFactory.openSession();
try {
session.beginTransaction();
session.delete(table);
session.getTransaction().commit();
} catch(Exception e) {
System.out.println("GET: "+e);
session.getTransaction().rollback();
}
session.clear();
}
@Override
public Table get(int id) {
// TODO Auto-generated method stub
Table table=new Table();
Session session=sessionFactory.openSession();
try{
final Transaction tx=session.beginTransaction();
table= (Table) session.get(Table.class,id);
session.getTransaction().commit();
} catch(Exception e) {
System.out.println("SAVE: "+e);
session.getTransaction().rollback();
} finally {
if(session != null) {
session.close();
}
}
session.clear();
return table;
}
@Override
public List<Table> list() {
// TODO Auto-generated method stub
List<Table> allTables=new ArrayList();
Session session=sessionFactory.openSession();
try {
session.beginTransaction();
org.hibernate.Query query=session.createQuery("FROM Table");
allTables=((Query) query).getResultList();
session.getTransaction().commit();
} catch(Exception e) {
System.out.println("LIST: "+e);
session.getTransaction().rollback();
}
session.clear();
return allTables;
}
}
I am running MySql through wamp and using hibernate and servlet in eclipse. I am getting this error ERROR: HHH000299: Could not complete schema update java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/demo
Servlet.service() for servlet [com.series.controller.TableController] in context with path [/HibernateProject] threw exception org.hibernate.TransactionException: Transaction not successfully started
And the following exception: SAVE: org.hibernate.exception.JDBCConnectionException: Could not open connection
I tried finding suitable driver on google but no luck. Please help