Checking for Database connection in JSP

T

teser3

I have a JSP that shows a JavaBean value that is fetched from my
Oracle database. The bean class uses a helper Database connection
class (DbConnClass) to connect to the database. Everything is
working where the bean fetches the database info and I use the Getter
and Setter methods to show the information. My only issue is how do
I show the JSP if the database is not available. Currently I have
ugly scriplets but was wondering if there is another way?

<%@ page import="java.sql.*, ..... " %>
<%
Connection connection = null;
connection = new DbConnClass().myConn();
%>

<jsp:useBean id="simple" class="mypack.MyBean">
<jsp:setProperty name="simple" property="name" />
</jsp:useBean>
Here is alot of static words in a couple paragraphs
etc.................
etc.............
Now showing dynamic value from Java Bean if database is available:
<%
if(connection != null)
{
%>
<jsp:getProperty name="simple" property="name" />
<%
}
else
{
out.write("Database is not available");
}
%>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top