Thank you for your answers... I know it's bad practice but I'm not the boss.
the boss wants a single connection for the application (or at least for each
session). And. he doesn't want to use beans... and he wants...

You now how this is...
Your example works so, as long as my boss is happy... I have suggested him
to use connection pooling and other techniques (as Java Beans or servlets)
but there's no way to change his mind.

Thank you again,
Mihai

-----Original Message-----
From: Morgan Delagrange [mailto:[EMAIL PROTECTED]]
Sent: Thursday, April 12, 2001 7:41 PM
To: [EMAIL PROTECTED]
Subject: Re: connection tag, please help!


I think what you mean to do here:

> <% session.setAttribute("conn1",conn1); %>

is actually:

  <% session.setAttribute("conn1",
       pageContext.getAttribute("conn1")); %>

However, as Marius pointed out in a previous email,
this is incredibly bad practice and no substitute for
proper connection pooling.

- Morgan

--- mihai manuta <[EMAIL PROTECTED]> 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(StatementImplT
> ag.java:137)
>       at
>
_0002fnew_0005fpage_0002ejspnew_0005fpage_jsp_7._jspService(_0002fnew_0005fp
> age_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.ja
> va: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:79
> 7)
>       at
>
org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
>       at
>
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpC
> onnectionHandler.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
>
>


=====
Morgan Delagrange
Britannica.com

__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail.
http://personal.mail.yahoo.com/

Reply via email to