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

From: "Dave Cramer" <Dave(at)micro-automation(dot)net>
To: "'Mihai Gheorghiu'" <tanethq(at)earthlink(dot)net>, <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 16:01:11
Message-ID: 019a01c18eef$b4c1eb20$8201a8c0@inspiron
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Velocity has a subproject called dvsl

http://jakarta.apache.org/velocity/dvsl/index.html

Which renders xml using velocity templates. Do you really want fop?

I also have an xml based report generator where you can define adhoc
selects in xml, and generate xml which is then transformed into
whatever(html/text/...) using a named stylesheet. If you are interested
in this I can open source it.

Dave

-----Original Message-----
From: pgsql-jdbc-owner(at)postgresql(dot)org
[mailto:pgsql-jdbc-owner(at)postgresql(dot)org] On Behalf Of Mihai Gheorghiu
Sent: Thursday, December 27, 2001 10:17 AM
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: [JDBC] Problem with connecting to postgres using JDBC with
JSP, but not JDBC with Java

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(Applic
>a
>tionFilterChain.java:247)
>
> at
>org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFil
>t
>erChain.java:193)
>
> at filters.ExampleFilter.doFilter(ExampleFilter.java:149)
> at
>org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applic
>a
>tionFilterChain.java:213)
>
> at
>org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFil
>t
>erChain.java:193)
>
> at
>org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperVal
>v
>e.java:243)
>
> at
>org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.j
>a
>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(StandardContextVal
v
>e.java:201)
>
> at
>org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.j
>a
>va:566)
>
> at
>org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authenticato
>r
>Base.java:472)
>
> at
>org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.j
>a
>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:23
4
>4)
> at
>org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.jav
a
>:164)
>
> at
>org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.j
>a
>va:566)
>
> at
>org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherV
>a
>lve.java:170)
>
> at
>org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.j
>a
>va:564)
>
> at
>org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.jav
>a
>:170)
>
> at
>org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.j
>a
>va:564)
>
> at
>org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:46
>2
>)
> at
>org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.j
a
>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.j
>a
>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,passwo
>r
>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

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
message can get through to the mailing list cleanly

Browse pgsql-jdbc by date

  From Date Subject
Next Message Mihai Gheorghiu 2001-12-27 16:06:13 Connection pooling
Previous Message tony 2001-12-27 14:57:21 Re: Problem with connecting to postgres using JDBC with JSP, but not JDBC with Java