In my application , login to database is written in dao class . If user enters wrong credentials , it has to be caught in SQLException cacth block . In my application it is not coming to catch block . In the console it is showing the exception .
Do any Spring inbuilt functions are caching ?? if so , how to overcome that . I want to show the error message to user in same page.
In my application , login to database is written in dao class . If user enters wrong credentials , it has to be caught in SQLException cacth block . In my application it is not coming to catch block . In the console it is showing the exception .
Do any Spring inbuilt functions are caching ?? if so , how to overcome that . I want to show the error message to user in same page.
Please help me on this ..
Are you using a Spring class/configuration to simplify your Data Access code. For instance, the JdbcTemplate catches SQLExceptions and converts them to DataAccessException instead.
try catching DataAccessException and see if that works for you.
Mark
Gireesh Mulage
Ranch Hand
Joined: Mar 08, 2010
Posts: 44
posted
0
Thank you for your reply ...
I am not using any Springs inbuilt functions for database connectivity . I am using Hibernate .
It is not catching in DataAccessException catch block also . how to overcome on this ?
Gireesh Mulage
Ranch Hand
Joined: Mar 08, 2010
Posts: 44
posted
0
I have tryed using @ExceptionHandler :
@ExceptionHandler(SQLException.class)
public String handleSQLException(SQLException ex ,HttpServletRequest request) {
It is not entering into this block too ...
Also , in dispatcher-servlet.xml i have entered bean tag as follows :
Hibernate does not throw SQLExceptions. It throws HibernateExceptions.
Mark
Gireesh Mulage
Ranch Hand
Joined: Mar 08, 2010
Posts: 44
posted
0
HI Mark ,
As i mentioned while initializing topic , in our application , user needs to select to which database to connect (not at the time of starting server ). So , in that if user enters wrong username/pswd , then even though I am using Hibernate to connect to DB , it throws SQLException for that . problem ! .
How if I use Spring's Hibernate API ? Will that support my scenario ?
May 2, 2011 2:31:54 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=aiops001, password=****}
May 2, 2011 2:32:00 PM org.hibernate.cfg.SettingsFactory buildSettings
WARNING: Could not obtain connection metadata
java.sql.SQLException: ORA-01017: invalid username/password; logon denied
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.O3log.receive2nd(O3log.java:496)
at oracle.jdbc.ttc7.TTC7Protocol.logon(TTC7Protocol.java:278)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:346)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:468)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:314)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:140)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:76)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2006)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1289)
at com.tcs.aiquery.dao.LoginHibDAO.connectToDB(LoginHibDAO.java:89)
at com.tcs.aiquery.client.LoginController.onSubmit(LoginController.java:78)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:626)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:150)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:354)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:342)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:763)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:709)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:613)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:536)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Thread.java:595)
May 2, 2011 2:32:00 PM org.hibernate.dialect.Dialect <init>
Have you tried stepping/debugging through that code to see exactly where the exception is thrown?
You are getting an SQLException, and looking at your code, it is possible that that is where it is being thrown, but it still feels like we are missing a piece of information. By stepping through code, you can see where it is being thrown and if it is even in that try portion of your code or elsewhere.
Are you using the LocalSessionFactoryBean in your Spring configuration to also create a sessionFactory?
Thanks
Mark
Gireesh Mulage
Ranch Hand
Joined: Mar 08, 2010
Posts: 44
posted
0
HI Mark ,
Exception is being thrown while creating session : i.e,
Your Dispatcher-servlet.xml would only contain beans on the web tier/layer. But something like your SessionFactory, DataSource etc would be defined in your middle tier/layer, and in a web application that middle tier would be loaded via Spring's ContextLoaderListener.
At this point, it looks like Hibernate is catching the SQLException and not bubbling it up. Although I would expect them to bubble it up as a HibernateException.
I don't think you will be able to change that. Unless there is more information about your setup/app that you aren't showing.