-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Error ocuurs: Cannot open connection
PostPosted: Thu Mar 04, 2010 11:20 am 
Newbie

Joined: Thu Mar 04, 2010 11:01 am
Posts: 2
Hi All,
I am new to hibernate. I am developing login module for my web application.
Here is 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;
}


When I run my application I got message " Cannot open connection"

Here is my config file

<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>

Please help me
Thanks in advance


Top
 Profile  
 
 Post subject: Re: Error ocuurs: Cannot open connection
PostPosted: Thu Mar 04, 2010 5:53 pm 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
can you post the error stacktrace?
Please post your code using code tag. It's hard to read your code.


Top
 Profile  
 
 Post subject: Re: Error ocuurs: Cannot open connection
PostPosted: Fri Mar 05, 2010 1:38 am 
Newbie

Joined: Thu Mar 04, 2010 11:01 am
Posts: 2
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"


Top
 Profile  
 
 Post subject: Re: Error ocuurs: Cannot open connection
PostPosted: Fri Mar 05, 2010 2:11 am 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
Code:
try {

}catch(Exception ex){
    //ex.printStackTrace();
    logger.error(e.getMessage(), e);
}


Can you change that part, so you can see the error more detail?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.