Re: Problem with connecting to postgres using JDBC with JSP, but not JDBC with Java

From: tony <tony(at)animaproductions(dot)com>
To: "'Peter Adamek'" <peter(dot)adamek(at)utoronto(dot)ca>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Problem with connecting to postgres using JDBC with JSP, but not JDBC with Java
Date: 2001-12-27 14:57:21
Message-ID: 6495795.1009465041477.JavaMail.root@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

... I'm also running
> Red Hat Linux 7.1. Switched over from NT 4.0. So please bear with me.
> I have used your suggestion Rene and tried connecting to my postgresql
> database using the "HelloPostgreSQL.java" pure JAVA (non-JSP) program
> located at http://www.fankhausers.com/postgresql/jdbc/. Running this
> enabled me to connect to the database, create tables, insert data,
> delete data and drop tables.
> Subsequent to this, I tried to modify my JSP code to also connect to the
> database (using the same connection string and all), but I kept on
> getting the following run time error in my browser:
> Apache Tomcat/4.0.1 - HTTP Status 500 - Internal Server Error type
> Exception report message Internal Server Error description The server
> encountered an internal error (Internal Server
> Error) that prevented it from fulfilling this request. exception
> java.lang.NullPointerException

Null pointers are your friend =:-D </joke>

If you can connect to your setup using JDBC/pure Java then you can using JSP. JSP is pure Java too.

Did you check my page? I guess you are using Tomcat 4. I haven't updated the site yet because I have had many problems understanding Catalina (new Tomcat engine).

Try using Tomcat 3.3 while you are on the learning curve. It is very straight forward getting contexts set up etc. You don't need Apache. It is there to serve static stuff faster than Tomcat can. I.E. all your form .html pages and whatnot.

I hope to have some time soon to get back into Tomcat 4 and am hoping that Ultradev5 will support something other than JSP 1.0

Cheers

Tony grant

--
tony(at)animaproductions(dot)com

JWebMail WebMail/Java v0.7.6 WWW to Mail Gateway
>From pgsql-jdbc-owner(at)postgresql(dot)org Thu Dec 27 10:26:17 2001
Received: from scaup.prod.itd.earthlink.net (scaup.mail.pas.earthlink.net [207.217.120.49])
by postgresql.org (8.11.3/8.11.4) with ESMTP id fBRFCnm03567
for <pgsql-jdbc(at)postgresql(dot)org>; Thu, 27 Dec 2001 10:12:49 -0500 (EST)
(envelope-from tanethq(at)earthlink(dot)net)
Received: from user-2ivesn2.dialup.mindspring.com ([165.247.114.226] helo=New6)
by scaup.prod.itd.earthlink.net with smtp (Exim 3.33 #1)
id 16JcDA-0003kC-00
for pgsql-jdbc(at)postgresql(dot)org; Thu, 27 Dec 2001 07:12:49 -0800
Message-ID: <003801c18ee9$9d1c8260$6e646464(at)New6(dot)Travel>
From: "Mihai Gheorghiu" <tanethq(at)earthlink(dot)net>
To: <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: Problem with connecting to postgres using JDBC with JSP, but not JDBC with Java
Date: Thu, 27 Dec 2001 10:17:29 -0500
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 4.72.3110.1
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
X-Archive-Number: 200112/183
X-Sequence-Number: 2688

A propos:
Has anyone tried to pipe Velocity into Fop? I need to come up with reports
that can match MS' formatting, and until now this is my best shot.
Any suggestion will be highly appreciated.
Thank you all.

-----Original Message-----
From: Dave Cramer <Dave(at)micro-automation(dot)net>
To: 'Peter Adamek' <peter(dot)adamek(at)utoronto(dot)ca>
Cc: pgsql-jdbc(at)postgresql(dot)org <pgsql-jdbc(at)postgresql(dot)org>
Date: Thursday, December 27, 2001 8:20 AM
Subject: Re: [JDBC] Problem with connecting to postgres using JDBC with JSP,
but not JDBC with Java

>Peter,
>
>As an aside, if you want to make the complete transition (IMO) have a
>look at velocity (http://jakarta.apache.org/velocity), or
>(www.webmacro.org) webmacro , and get rid of JSP too!
>
>I see you are at U of T, I am in Orangeville!
>
>Cheers,
>
>Dave
>
>-----Original Message-----
>From: pgsql-jdbc-owner(at)postgresql(dot)org
>[mailto:pgsql-jdbc-owner(at)postgresql(dot)org] On Behalf Of Peter Adamek
>Sent: Thursday, December 27, 2001 2:16 AM
>To: Jens Carlberg
>Cc: pgsql-jdbc(at)postgresql(dot)org
>Subject: [JDBC] Problem with connecting to postgres using JDBC with JSP,
>but not JDBC with Java
>
>
>First off, many thanks to Rene Pijlman, Jens Carlberg and K.Ari
>Kruprikov for your previous emails regarding the subcect Problem with
>connecting to postgres using jdbc7.0-1.2.jar. Your suggestions have
>been very informative.
>
>I must confess, I am somewhat new to JSP and Java as a whole. My
>background is in ASP development and I am dying to fully convert over.
>I am getting the hang of things pretty well. I have a full arsenal of
>Oreiley and Wrox books I've gone out to purchase at my disposal on Java
>2, JSP 2nd eddition, Databases with PostgreSQL, etc. I'm also running
>Red Hat Linux 7.1. Switched over from NT 4.0. So please bear with me.
>
>I have used your suggestion Rene and tried connecting to my postgresql
>database using the "HelloPostgreSQL.java" pure JAVA (non-JSP) program
>located at http://www.fankhausers.com/postgresql/jdbc/. Running this
>enabled me to connect to the database, create tables, insert data,
>delete data and drop tables.
>
>Subsequent to this, I tried to modify my JSP code to also connect to the
>database (using the same connection string and all), but I kept on
>getting the following run time error in my browser:
>
>Apache Tomcat/4.0.1 - HTTP Status 500 - Internal Server Error type
>Exception report message Internal Server Error description The server
>encountered an internal error (Internal Server
>Error) that prevented it from fulfilling this request. exception
>java.lang.NullPointerException
> at TestServlet.service(TestServlet.java:40)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
> at
>org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica
>tionFilterChain.java:247)
>
> at
>org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt
>erChain.java:193)
>
> at filters.ExampleFilter.doFilter(ExampleFilter.java:149)
> at
>org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica
>tionFilterChain.java:213)
>
> at
>org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt
>erChain.java:193)
>
> at
>org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValv
>e.java:243)
>
> at
>org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.ja
>va:566)
>
> at
>org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:4
>72)
> at
>org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
> at
>org.apache.catalina.core.StandardContextValve.invoke(StandardContextValv
>e.java:201)
>
> at
>org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.ja
>va:566)
>
> at
>org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authenticator
>Base.java:472)
>
> at
>org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.ja
>va:564)
>
> at
>org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:4
>72)
> at
>org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
> at
>org.apache.catalina.core.StandardContext.invoke(StandardContext.java:234
>4)
> at
>org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java
>:164)
>
> at
>org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.ja
>va:566)
>
> at
>org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherVa
>lve.java:170)
>
> at
>org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.ja
>va:564)
>
> at
>org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java
>:170)
>
> at
>org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.ja
>va:564)
>
> at
>org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:462
>)
> at
>org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.ja
>va:564)
>
> at
>org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:4
>72)
> at
>org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
> at
>org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.
>java:163)
>
> at
>org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.ja
>va:566)
>
> at
>org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:4
>72)
> at
>org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
> at
>org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.j
>ava:1011)
>
> at
>org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:
>1106)
>
> at java.lang.Thread.run(Thread.java:484)
>
>At this point, I followed Jens suggestion to modify my code to the
>following. In the following code, I don't run any SQL statements
>against the database, but after attempting to make the database
>connection, I check to see if it (the connection) is equal to null and
>sure enough it is. This is what was generating the above error. So at
>this point, I'm not sure of what to do to. I think my problem is in the
>way the drivers or classes are being initialized, but I'm not sure. I
>have folllowed the standard way to connect to the database as has been
>suggested in the books and on numerous sites, but nothing seems to work.
>I know the connection string works fine, becuase the same one works in
>my "HelloPostgreSQL.java" pure JAVA (non-JSP) program.
>
>One thing that I am thinking is that it may be the way I am running
>Tomcat. I have downloaded the binary, untared it as su and when I run
>the startup script, I run it as su (standalone without having it be
>integrated with Apache). Could this present some problem? What context
>would you suggest running Tomcat as (there seems to be very limited
>documentation on this)? If I should run it as another user, I supposes
>I have to change the ownership of all files in the $TOMCAT_HOME tree to
>that user context otherwise I may not get permission to certain files.
>I am also in the middle of trying to integrate my Tomcat with Apache to
>see if maybe that type of setup will do the trick. Any suggestions once
>again would be greatly appreciated (and don't be afraid to say the
>obvious - it may not be obvious to me). Many thanks again to Rene, Jens
>and Ari.
>
>import java.io.*;
>import javax.servlet.*;
>import javax.servlet.http.*;
>import java.sql.*;
>
>public class TestServlet extends HttpServlet {
>
> Connection db;
> String database = "peter";
> String username = "myLogin";
> String password = "myPassword";
>
> public void init (ServletConfig config) throws ServletException {
> super.init(config);
>
> /* Load the driver */
> try {Class.forName("org.postgresql.Driver");}
> catch (ClassNotFoundException e) {}
>
> /* Connect to the database */
> try {db >DriverManager.getConnection("jdbc:postgresql:"+database,username,passwor
>d);}
>
> catch (SQLException e) {}
> }
>
> public void service (HttpServletRequest request,HttpServletResponse
>response) throws ServletException, IOException {
> // set content type and other response header fields first
> response.setContentType("text/html");
>
> // get the communication channel with the requesting client
> PrintWriter out = response.getWriter();
>
> /* Standard top bit */
> out.println("<HTML>\n"
> + "<HEAD>\n"
> + " <TITLE>Test</TITLE>\n"
> + "</HEAD>\n"
> + "<BODY BGCOLOR=\"#FFFFFF\">\n");
>
> if (db = null) {
> out.println("Database is not being opened.<br>");
>
> }
>
> /* Standard bottom bit */
> out.println("</BODY>\n"
> + "</HTML>\n");
> out.close();
> }
>
> public void destroy() {
> try {db.close();}
> catch (SQLException e) {}
> }
>}
>
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)
>
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 4: Don't 'kill -9' the postmaster

Browse pgsql-jdbc by date

  From Date Subject
Next Message Dave Cramer 2001-12-27 16:01:11 Re: Problem with connecting to postgres using JDBC with JSP, but not JDBC with Java
Previous Message Nick Fankhauser 2001-12-27 13:25:06 Re: Problem with connecting to postgres using JDBC with JSP, but not JDBC with Java