-->
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.  [ 3 posts ] 
Author Message
 Post subject: Configuring username / password for Connection
PostPosted: Fri Jan 05, 2007 8:22 pm 
Newbie

Joined: Fri Jan 05, 2007 8:08 pm
Posts: 2
Hi, I have an Rich Client Applictation (RCP) which uses Hibernate.

I want individual users to access the underlying DB with their corresponding accounts.
I create a new Hibernate Configuration, letting it populate all properties from the standard hibernate conf xml file, but before creating the SessionFactory, i set the username/password properties programmatically, and then create the Factory.

This works well if username and password are correct.

However, if they are not, I have no way to catch Exceptions while Hibernate or the connection pooling I'm using (c3po) throws Exceptions, since they seem to be catched by Hibernate, and it seems that my app runs into timeouts before any stacktraces are written to err.out. I have no chance to provide feedback to the user.

What I want is this: just after my application launches, ask the user for his DB username and password (a classic login screen), and then configure Hibernate to use those credentials. If they are ok, run the application. If they are not, prompt the ueser with info that his credentials are wrong.

How should I do this ? Obviously, the way I'm doing it now is the wrong approach.

Thanks for any suggestions.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 06, 2007 9:05 am 
Newbie

Joined: Mon Dec 25, 2006 3:14 pm
Posts: 18
the getConnection of the DataSource throws SQLException[1], which would be wrapped with HibernateException. So, you should look at
the cause and make out whether the username/password is correct. For example:

try{
session.saveOrUpdate(object);
} catch(HibernateException e) {
Throwable cause = e.getCause();
if(cause instanceof SQLException) {
SQLExeption sqlEx = (SQLException) cause;
// check the vendor code/sql state to identify the login/password is correct.
}
}

[1] http://www.mchange.com/projects/c3p0/ap ... ang.String,
java.lang.String)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 06, 2007 9:39 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Or maybe just try to connect using direct jdbc with the given credentials, then only use these credentials in Hibernate if you could for example perform a query like "select 1 from dual" on an Oracle dbms?

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.