JSP Database connection with Bean
Posted on 2002-04-17
I currently use the following code to connect to an oracle database from a JSP page:
<jsp:useBean id="db" scope="session" class="mypackage.mybean" />
Connection Conn = null;
Conn = db.Connect("db","user","pass");
The Bean code looks something like this:
public Connection Connect (String dbname,String user,String pass) throws ClassNotFoundException,SQLException
conn Connection = null;
conn = DriverManager.getConnection(
This works fine, except, I need both the Oracle errormessage (if one exists) and the connection object returned from the bean.
Currently with above code, I get the connection object back, which I need to pass on to other pages where the user need to be identified, but what if an error occurs?, then I only get the default Tomcat error "null pointer exception" instead of an oracle error which I can display.
I have also tried doing the whole connection in the bean and return a string object to JSP, in which case if I get an empty string back, I know the connection was made, and if not, I get the bean to pouplate the errormessage in the return string. But then I have no connection object for other pages that the user might browse to.
Am I missing something obvious?