Skip to Content
0
Former Member
Nov 23, 2006 at 10:52 AM

Error in connecting to database using a datasource in a jsp file

64 Views

Dear SDN's,

I have a program which retreives Data from the Employee table and displays on portal page.

What i have done is,

I have created a pageprocessor component, with 2 jsp files one is for data insert and other is for retriving the data from the database table.

For inserting the records, i have written the code in the Even handling method of Page Proceessor component.

For retriving the data i have written the following jsp code in the jsp file and this i am calling in PBO of pageprocessor component based on the condition.

When i try to insert the records it is working fine.But i am getting an error when try to execute the retreving the records in other jsp.

Please go through the following code and correct me if anything is wrong here.

<b><%@ page language="java" %>

<%@ page import ="java.lang.*,java.sql.Connection,javax.sql.DataSource,java.sql.Statement,java.sql.ResultSet,javax.naming.InitialContext" %>

<body>

<center>

<table border="1">

<tr cellpadding="1">

<th>Empid</th>

<th>Name</th>

<th>City</th>

</tr>

<%

InitialContext initialContext = new InitialContext();

DataSource ds = (DataSource) initialContext.lookup("jdbc/MyDS");

Connection conn = ds.getConnection();

stmt = conn.createStatement();

ResultSet rs=stmt.executeQuery("select * from EMP_DETAILS");

while(rs.next())

{

out.println(rs.getString("EMPID"));

out.println(rs.getString("NAME"));

out.println(rs.getString("CITY"));

}

%>

<tr cellpadding="1">

<td><%=rs.getString("EMPID")%></TD>

<TD><%=rs.getString("NAME")%></td>

<td><%=rs.getString("CITY")%></td>

<br>

}

</table>

catch (Exception e) {

e.printStackTrace();

out.println("Exception" + e);

}</b>

The error what i am getting is.

Portal Runtime Error

An exception occurred while processing a request for :

iView : JSPdbProject.Empjava

Component Name : JSPdbProject.Empjava

Error occurs during the rendering of jsp component.

Exception id: 04:29_16/11/06_0005_507480350

See the details for the exception ID in the log file