Code:
public boolean validateUser(){
boolean bool=false;;
try {
SessionFactory sessionFactory =
new Configuration().configure()
.buildSessionFactory();
Session session =sessionFactory.openSession();
org.hibernate.Transaction tx = session.beginTransaction();
tx = session.beginTransaction();
String SQL_QUERY ="Select tbllogin.username,tbllogin.password" ;
Query query = session.createQuery(SQL_QUERY);
for(Iterator it=query.iterate();it.hasNext();){
Object[] row = (Object[]) it.next();
if(name.equals(row[0].toString())&& pass.equals(row[1].toString())){
bool=true;
}else{
bool=false;
}
}
tx.commit();
session.close();
}catch(Exception e){
System.out.println(e.getMessage());
return false;
}
return bool;
}
Here is config file
Code:
<session-factory>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.url">jdbc:mysql://localhost:3036/mysql/projectmanagement</property>
<property name="connection.username">root</property>
<property name="connection.password">pass</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="myeclipse.connection.profile">MySql</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<!--thread is the short name for
org.hibernate.context.ThreadLocalSessionContext and let Hibernate
bind the session automatically to the thread
-->
<property name="current_session_context_class">thread</property>
<!-- this will show us all sql statements -->
<property name="hibernate.show_sql">false</property>
<mapping resource="ode/servlet/Login.hbm.xml" />
</session-factory>
I am working in MyEclipse, when submitting my login form console prints
" Cannot open connection"