IBM Support

JSP Page to test and debug access to a datasource

Troubleshooting


Problem

The following JSP page will allow you to test if a datasource is setup properly in your appserver.

Resolving The Problem

I have setup a datasource on my appserver and am getting an error how can I test to make sure the datasource is working properly?

Create a jsp file called ds.jsp in the location listed in the table below.

Place the file in the location listed here:

JSP location
Appserver Location
JBoss process-server/applications/teamworks.ear/teamworks.war/html
Bea process-server/applications/teamworks.ear/teamworks/html
Bea 9.2 process-server/servers/twprocsvr/stage/teamworks/teamworks.ear/teamworks/html
WebSphere installedApps/yourCell/teamworks.ear/teamworks.war/html



Cut and paste the code at the bottom of this article into ds.jsp and save the file.

Once saved, you will access the page as http://host:port/teamworks/ds.lsw. Enter the name of the datasource and click submit. If there is an error you will get a detailed stacktrace.

The jsp code:

----------- cut here ------------
<%@page import="java.sql.*, java.io.*, javax.sql.DataSource, javax.naming.*"%>

<%!
String dsName = "jdbc/TeamWorksDB";
%>
<%
String req = request.getParameter ("dsName");
if (req != null) {
dsName = req;
}
%>
<form method="post" action="<%=request.getRequestURI()%>">
Enter Datasource Name:<input type="text" value="<%=dsName%>" name="dsName"/><br>
<input type="submit" value="submit"/>
</form>

<%
try {
String driver = "";
String db = "";


if (!dsName.equals("")) {
InitialContext ctx = new InitialContext();
DataSource dataSource = (DataSource) ctx.lookup (dsName);
Connection con = dataSource.getConnection();
DatabaseMetaData dmd = con.getMetaData();
db = dmd.getDatabaseProductName() + " " + dmd.getDatabaseProductVersion();
driver = dmd.getDriverName() + " " + dmd.getDriverVersion();

%>
Success! We looked up and got a connection to <%=dsName%><br>
Database: <%=db%> <br>
Driver version: <%=driver%><br>
<%
}
}
catch (Exception e) {
PrintWriter pw = new PrintWriter (out);
%>
There was an exeption getting a connection to or looking up the datasource:<%=dsName%><br>
        <%
        e.printStackTrace (pw);
        %>
    

<%

}
%>

----------- cut here ------------
[{"Product":{"code":"SSFPRP","label":"WebSphere Lombardi Edition"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Not Applicable","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF010","label":"HP-UX"},{"code":"PF016","label":"Linux"},{"code":"PF027","label":"Solaris"},{"code":"PF033","label":"Windows"}],"Version":"6.2.2;6.2.1;6.2;6.1;6.0.1","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}}]

Historical Number

212

Document Information

More support for:
WebSphere Lombardi Edition

Software version:
6.2.2, 6.2.1, 6.2, 6.1, 6.0.1

Operating system(s):
AIX, HP-UX, Linux, Solaris, Windows

Document number:
139369

Modified date:
15 June 2018

UID

swg21439685

Manage My Notification Subscriptions