As far as I know the connection is stored in the page context
and not in the session, that is why you get the null pointer.

You should open and close the connection in every page you
need one.

Marius


> mihai manuta wrote:
> 
> Hello,
> 
> I need to create a connection in one page and then pass the same connection to 
>another page.
> The following is an example of what I've done:
> 
> FIRST FILE:
> 
> <%@ taglib uri="http://jakarta.apache.org/taglibs/jdbc" prefix="sql" %>
> 
> <html>
> <head>
>         <title>JSP Test</title>
> </head>
> 
> <body>
> 
> <%
>                     String driver   = "dirver";
>                     String user     = "user";
>                     String password = "password";
>                     String host     = "url";
> %>
> 
> <font color="Green" face="Arial">trying to establish a connection...
> 
> <br>
> 
> <sql:connection id="conn1">
>           <sql:url><%=url%></sql:url>
>           <sql:driver><%=driver%></sql:driver>
>           <sql:userId><%=user%></sql:userId>
>           <sql:password><%=password%></sql:password>
> </sql:connection>
> connection established...
> <br>
> 
> <table>
>         <sql:statement id="qGetParam" conn="conn1">
>         <sql:query>
>                 select * from attachedfile
>         </sql:query>
>         <sql:resultSet id ="rs1">
>         <tr>
>           <td><sql:getColumn position="3"/></td>
>     </tr>
>         </sql:resultSet>
>         </sql:statement>
> </table>
> 
> <%=conn1%>
> 
> <% session.setAttribute("conn1",conn1); %>
> 
> <a href="Page2.jsp">xxx</a>
> 
> </font>
> </body>
> </html>
> 
> SECOND FILE:
> 
> <%@ taglib uri="http://jakarta.apache.org/taglibs/jdbc" prefix="sql" %>
> 
> <%@ page import="java.sql.*" %>
> 
> <html>
> <head>
>         <title>JSP Test</title>
> </head>
> 
> <body>
> 
> <% Connection conn1 = (Connection)session.getAttribute("conn1"); %>
> 
> <%=conn1%><br>
> 
> <%
>         Statement stmt=conn1.createStatement();
>         ResultSet rs=stmt.executeQuery("select * from attachedfile");
>         rs.next();
> %>
> <br>
> <%=rs.getString(3)%>
> 
> <table>
>         <sql:statement id="qGetgf" conn="conn1">
>         <sql:query>
>                 select * from attachedfile
>         </sql:query>
>         <sql:resultSet id ="rgf">
>         <tr>
>           <td><sql:getColumn position="3"/></td>
>     </tr>
>         </sql:resultSet>
>         </sql:statement>
> </table>
> 
> </body>
> </html>
> 
> Everithing works just fine until I try to use the connection stored in session from 
>the first page to create another statement
> (using tag lib). At that point I get an exeption
> 
> Root cause:
> 
> java.lang.NullPointerException
>         at 
>org.apache.taglibs.jdbc.statement.StatementImplTag.doStartTag(StatementImplTag.java:137)
>         at 
>_0002fnew_0005fpage_0002ejspnew_0005fpage_jsp_7._jspService(_0002fnew_0005fpage_0002ejspnew_0005fpage_jsp_7.java:109)
>         at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>         at 
>org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:177)
>         at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:318)
>         at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:391)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>         at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
>         at org.apache.tomcat.core.Handler.service(Handler.java:286)
>         at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
>         at 
>org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)
>         at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
>         at 
>org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:210)
>         at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
>         at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
>         at java.lang.Thread.run(Thread.java:484)
> 
> that I have no ideea what it means. The connection exists, it's executing the querry 
>(from the first part)... but...
> what can I do?!
> Please help!
> 
> Mihai Manuta

-- 
------------------
Marius Scurtescu, Software Engineer
Tel: (604) 899-2835 Fax: (604) 899-2899
mailto:[EMAIL PROTECTED]
Multiactive Software Inc. http://www.multiactive.com
------------------
Attract and retain customers with Multiactive Software --
proud winners of PC WEEK's "Best of COMDEX" award.
------------------

Reply via email to