DB2 Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDB2 Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 26th, 2004, 04:06 AM
nicohall nicohall is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 5 nicohall User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
JasperException trying to connect to DB2 via jsp

Hi,

i'm trying to run a jsp in order to test a connection with DB2
I'm using :
tomcat 4.1.24
jsdk1.4.1_01
DB2 8.1


here is the jsp :
<html>
<body>
<%try {
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
javax.naming.InitialContext ctx = new javax.naming.InitialContext();
%>
Contexte JNDI : <%=ctx%><br>
<% javax.sql.DataSource ds =
(javax.sql.DataSource)ctx.lookup("java:comp/env/jdbc/masource"); %>
DataSource : <%=ds%><br>
<% java.sql.Connection connection = ds.getConnection(); %>
Connexion : <%=connection%><br>
<%
connection.close();
} catch (Exception e) {
%>
Error : <%=e%>
<%
}
%>
</body>
</html>
----end of the jsp

when i run the jsp, here is the Exception i get :

org.apache.jasper.JasperException NoAllocEnv
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:254)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.j ava:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.j ava:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.j ava:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.j ava:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.j ava:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.j ava:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:594)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.jav a:392)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
at java.lang.Thread.run(Thread.java:536)

-----end of the stack trace

with no "root cause"

I know this stack trace doesn't mean very much and that's why i don't understand what's wrong

Reply With Quote
  #2  
Old May 28th, 2004, 04:28 PM
dcaillouet's Avatar
dcaillouet dcaillouet is offline
Big Endian
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: May 2001
Location: Fly-over country
Posts: 1,173 dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 16 h 29 m 5 sec
Reputation Power: 24
Quote:
i'm trying to run a jsp in order to test a connection with DB2
I can't tell from the stack trace what the problem is either. Specifically, I can't tell if the problem is with DB2, Tomcat or your code. My first question would be have you tested your connection from a command prompt yet? In other words if you're running this on a *nix box, have you logged in as the instance owner and run the command:

db2 CONNECT TO database USER userid USING password

Do you connect okay? Once we determine if your connection / environment is setup correctly, then we can look at other things that might be causing this problem.

Reply With Quote
  #3  
Old May 29th, 2004, 12:36 PM
Nemi Nemi is offline
Clueless llama
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Feb 2001
Location: Lincoln, NE. USA
Posts: 2,353 Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Days 12 h 35 m 19 sec
Reputation Power: 111
ALso, you may want to see what can throw an exception and put some try/catch blocks in there. For instance, the InitialContext.lookup() method throws a NamingException. If you do this you may be better able to track down which piece is causing your problem.
__________________
~Nemi

Before posting did you try:
[ Javadocs | Google ]

Reply With Quote
  #4  
Old June 1st, 2004, 03:57 AM
nicohall nicohall is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 5 nicohall User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks for your responses,
The database is fine, i can connect, create table etc... from db2 command line
Tomcat works fine too : i manage to deploy a war and view some simple jsp.

I tried to run a simple java binary :

============================
import java.sql.*;

class Test1 {

public static void main (String[] args) {
try {

// Step 1: Load the JDBC driver.
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");

// Step 2: Establish the connection to the database.
String url = "jdbc:db2:foodmart";
Connection conn = DriverManager.getConnection(url,"user1","password");

} catch (Exception e) {
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
}
}
}
===========================

That code works fine but when i tried to run the jsp equivalent, i got the same exception than before (SQLAllocEnv)

I watch on the db2 documentation to know what is it (http://www-306.ibm.com/cgi-bin/db2w...7l0sqll1302.htm) but i really don't know how i can interfere with that or make something to correct the problem.

Also, my OS is windows2k.

the problem is not jndi so i didn't try to catch a NamingException

Thank you for your help

Reply With Quote
  #5  
Old June 1st, 2004, 12:35 PM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 4,840 Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 2 Days 36 m 16 sec
Reputation Power: 88
Send a message via ICQ to Onslaught
Well lets try looking at this a little different.
What version of DB2 are you running?
Have you tried to install the latest patches for that version yet?

Reply With Quote
  #6  
Old June 2nd, 2004, 03:17 AM
nicohall nicohall is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 5 nicohall User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
The version of DB2 is 8.1.0 and there is no patch installed.

I didn't find any patch or update that could correct the problem, but maybe I didn't search well...

Regards

Reply With Quote
  #7  
Old June 3rd, 2004, 03:20 AM
nicohall nicohall is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 5 nicohall User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi,

i have tried another way to run the jsp under tomcat :
The product of my company have is own tomcat(4.1.18), which is well configured with db2. So, i tried to run my jsp under this tomcat and it's work. but when i tried to run another jsp to connect database using jndi, it failed (the source code is very basic and correct)

It's because the web.xml of my webapp don't use the same tags-set (those of servlet 2.3) than what is instaled in tomcat 4.1.18 (servlet 2.2). So those tags aren't recognized : <filter>, <filter-mapping>, <listener>

So, it's definitively a problem in the configuration of tomcat, but I can't understand what's wrong.


Maybe should i repost this question in another forum ?

Reply With Quote
  #8  
Old June 3rd, 2004, 08:33 AM
Nemi Nemi is offline
Clueless llama
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Feb 2001
Location: Lincoln, NE. USA
Posts: 2,353 Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Days 12 h 35 m 19 sec
Reputation Power: 111
It is either a tomcat configuration error or a jndi error. Catching the exceptions thrown like I suggested may have helped track this down.

Since you have narrowed it down to a java problem, I would suggest posting this question in the java forum.

Reply With Quote
  #9  
Old June 3rd, 2004, 10:31 AM
nicohall nicohall is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 5 nicohall User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thank you for your response,

I have found what's wrong : i feel a little miserablous.... In fact, it was the driver db2java.zip which was corrupted.

I have replaced it and now, it works fine

Regards

Reply With Quote
  #10  
Old November 28th, 2006, 09:49 PM
spamidighantam spamidighantam is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2006
Posts: 1 spamidighantam User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 m 39 sec
Reputation Power: 0
JSP connecting with DB2

Hi,

I also have the project on jsp with DB2. Could you please explain what are the softwares needed to connect to DB2 and also please send your JSP code for connection.

Now I have Apache Tomcat 5.5. Should I download db2jdbc driver ?

Thanks in advance,
Sreedhar

Reply With Quote
  #11  
Old March 13th, 2007, 01:32 PM
neha_dhawan neha_dhawan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Posts: 1 neha_dhawan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 48 sec
Reputation Power: 0
DB2 connectivity with netbeans

i have been trying to connect the netbeans 3.5.1 with DB2 version 8.1 by establihsing a connection through the db2 driver "COM.ibm.db2.jdbc.app.DB2Driver".
the connection is established, the code is compilng without errors, but on execution its not giving any output.

the jsp code i wrote is:-
[code]
<%
try
{
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
Connection con=DriverManager.getConnection("jdbc:db2:db");
Statement stmt=con.createStatement();
ResultSet rs= stmt.executeQuery("select * from st");
while(rs.next())
{ out.println(rs.getInt(1));
}
}
catch(ClassNotFoundException ex)
{
System.out.println(ex);
}

catch(SQLException ex)
{
System.out.println(ex);
}
catch(Exception e)
{ out.println(e);
}
%>
where "db" is the database name & "st" is table name

can someone plz help me wid my problem???

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDB2 Development > JasperException trying to connect to DB2 via jsp


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |