-->
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.  [ 1 post ] 
Author Message
 Post subject: How to catch exception while validating the usrname & pa
PostPosted: Tue Apr 07, 2009 1:46 am 
Newbie

Joined: Tue Apr 07, 2009 1:30 am
Posts: 3
Location: Chennai, India.
Hi,


Im setting the username and password for the hibernate.cfg.xml dynamically like the following code.

Code:
public class Sessions implements QueriesInterface{

   private static SessionFactory sessionFactory;
   private static Configuration configuration = new Configuration();

   static {
      try {
         String userName = GuigenserviceImpl.userName;
         String password = GuigenserviceImpl.password;
         String hostName = GuigenserviceImpl.hostName;
         String portNo = GuigenserviceImpl.portNo;
         String sId = GuigenserviceImpl.sId;

         // Create the SessionFactory from hibernate.cfg.xml
         configuration
               .setProperty("hibernate.connection.username", userName);
         configuration
               .setProperty("hibernate.connection.password", password);
         configuration.setProperty("hibernate.connection.url",
               connection_url + hostName + ":" + portNo + ":" + sId);
         configuration.configure("/hibernate.cfg.xml");

         sessionFactory = configuration.buildSessionFactory();
         sessionFactory.openSession();
         GuigenserviceImpl.strAccpted = "true";
      } catch (Throwable ex) {
         // Make sure you log the exception, as it might be swallowed
         GuigenserviceImpl.strAccpted = "false";
         ex.printStackTrace();
         configuration = null;
         sessionFactory = null;
         throw new ExceptionInInitializerError(ex);
      }
   }

   /**
    * The session factory is created at class load time and is * provided here.
    */

   public static SessionFactory getSessionFactory() {
      return sessionFactory;
   }


While the configuration.configure() executes, it is setting up my dynamic username and password to the configuration file.

Suppose if im giving wrong username and password means, it shows SQLException in console. But in the code, it is not going to catch block. The program is executing normally.

So can anyone tell me how to catch the exception thrown during the time of wrong username and password was given.

Also see my post regarding this topic on the following URL.

http://www.coderanch.com/t/439701/Object-Relational-Mapping/java/catch-exception-while-validating-username

Thanks in advance.

_________________
Thanks & Regards,
Kothandaraman N.


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

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.