Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Datasource lookup problem, Websphere 4, JSP

843854Sep 19 2002 — edited Jun 27 2003
Hi,
I wrote the following jsp and i could not access database. We have DB2 universal database running on some other machine in the nerwork and i have downloaded Websphere Application Single server 4.1 and my enviroment is Windows NT. I copied db2.java.zip file from DB2 machine to my system. My configured driver and datasource as follows.

DB2Driver Properties
Server Class Path: E:\DB2Driver\db2java.zip
Name: Db2JdbcDriver
Implementation Classname: COM.ibm.db2.jdbc.DB2ConnectionPoolDataSource

Datasource Properties
Name: DB2 Connection datasource
JNDI Name: jdbc/Connection
Database Name: devserver2:6789/mser
Default User ID: xxxx
Default Password: xxxx

JSP FILE:

<FORM name="mail" METHOD="post">
<%@ page import="java.util.*,java.io.*,java.text.*,java.sql.*,javax.naming.*,COM.ibm.db2.jdbc.net.DB2Driver" %>

<%

java.util.Properties parms = new java.util.Properties();

// I tried with com.ibm.websphere.naming.WsnInitialContextFactory

parms.setProperty (Context.INITIAL_CONTEXT_FACTORY, "com.ibm.ejs.ns.jndi.CNInitialContextFactory");
javax.naming.Context ctx = new javax.naming.InitialContext(parms);

// I tried java:comp/env/jdbc/Connection. It throwed an error Name comp/env/jdbc not found in context "java:"

javax.sql.DataSource ds = (javax.sql.DataSource) (ctx.lookup("jdbc/Connection"));
java.sql.Connection conn = ds.getConnection();
java.sql.Statement stmt = conn.createStatement();
java.sql.ResultSet r = stmt.executeQuery("SELECT * FROM TDM_DME_FORMULARY");
while (r.next()){
String a=r.getString("GROUP");

%>

<table>
<tr valign=top align=left bgcolor=#ffffff>
<td align="left" width="20%"><font class="fntreR">Additional Documentation</font></td>
<td align="center" valign="center"><INPUT type="text" name="adddoc" value="<%=a%>" size="70" maxlength="80"></td>
</tr>

</table>

</form>
<%
}
stmt.close();
conn.close();
%>


and i am getting the following ERROR:
Exception occurred while the JNDI NamingManager was processing a javax.naming.Reference object.

Any suggestions???

NOTE: When i am using driver manager instead of datasource i am able to connect database and retrieving data.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 25 2003
Added on Sep 19 2002
14 comments
1,014 views