Re: Tomcat 4.0.4, jndi, jdbc and postgresql [long]

2002-07-03 Thread Przemyslaw Kowalczyk

On Tuesday 02 July 2002 16:27, Les Hughes wrote:
 Ok. Summary time.

 Martin reflects my experience - I dumped tyrex and used DBCP as well. But
 aren't we trying to go direct without a pool? Having said that I've only
 ever managed to get datasources working when DBCP is being used...

 Check that your driver jarfile does not contain the javax.sql extension
 classes. If it does, delete them and rejar. Some versions of Tomcat will
 ignore any jar that has these classes present. Be careful with this thought
 - I work with jdk1.4 which has these built in.

 Also, you don't specify a DataSourceFactory in your server.xml - see below.


 Here's a known (well as far as I know...) good postgres solution using
 DBCP.

And that's the path I'll follow. Despite huge support from the list (I applied 
all suggested changes and patches) I was unable to make it work. Now I will 
try to understand the new model of DBCP.

Thank you all for your support.

przem


--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




Tomcat 4.0.4, jndi, jdbc and postgresql [long]

2002-07-02 Thread Przemyslaw Kowalczyk

Hi

I've just started to write servlets. Servlets that only do processing, without 
connecting to database work fine, but I have some problems to get the 
connection with postgresql via jdbc work.

Tomcat: 4.0.4   (on linux)
Postgresql: 7.2.1 (on linux)
Jdbc: pgjdbc2.jar (from jdbc.postgresql.org)

The servlet is quite simple:

import java.io.*;
import java.util.*;
import java.sql.*;
import javax.sql.*;
import javax.naming.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class InfoServlet extends HttpServlet {

Connection con;
private boolean conFree = true;

public void init() throws ServletException {
try  {
Context initCtx = new InitialContext();
Context envCtx = 
(Context)initCtx.lookup(java:comp/env);
DataSource ds = (DataSource)
envCtx.lookup(jdbc/BookDB);
Connection con = ds.getConnection();
} catch (Exception ex) {
throw new ServletException(Couldn't open connection 
to database:  + ex.getMessage());
}
}

public void destroy() {
try {
con.close();
} catch (SQLException ex) {
System.out.println(ex.getMessage());
}
}

public void doGet (HttpServletRequest request, HttpServletResponse 
response) throws ServletException, IOException {

HttpSession session = request.getSession();

// set content-type header before accessing the Writer
response.setContentType(text/html);
response.setBufferSize(8192);
PrintWriter out = response.getWriter();

// then write the data of the response
out.println(html +
headtitleDuke's Bookstore/title/head);
}
}

in web/WEB-INF/web.xml I defined:


!DOCTYPE web-app
PUBLIC -//Sun Microsystems, Inc.//DTD Web Application 2.3//EN
http://java.sun.com/dtd/web-app_2_3.dtd;
web-app
display-nameCurrency Converter Application/display-name
description
Test servlet
/description
servlet
servlet-nameinfo/servlet-name
display-nameinfo/display-name
descriptionno description/description
servlet-classInfoServlet/servlet-class
/servlet
servlet-mapping
servlet-nameinfo/servlet-name
url-pattern/info/url-pattern
/servlet-mapping
session-config
session-timeout30/session-timeout
/session-config
resource-ref
res-ref-namejdbc/BookDB/res-ref-name
res-typejavax.sql.DataSource/res-type
res-authContainter/res-auth
/resource-ref
/web-app

And in server.xml in the contex of the application:

   Context path=/bookstore docBase=bookstore debug=0
 reloadable=true crossContext=true
  Logger className=org.apache.catalina.logger.FileLogger
 prefix=localhost_bookstore_log. suffix=.txt
  timestamp=true/
  Resource name=jdbc/BookDB auth=Container
type=javax.sql.DataSource/
  ResourceParams name=jdbc/BookDB
parameter
  nameuser/name
  valuejava/value
/parameter
parameter
  namepassword/name
  valuejava/value
/parameter
parameter
  namedriverClassName/name
  valueorg.postgresql.Driver/value
/parameter
parameter
  namedriverName/name
  valuejdbc:postgresql:public/value
/parameter
  /ResourceParams
/Context

I've tried a few different driverName parameters: (restarting Tomcat after 
each change)
jdbc:postgresql://localhost/public
jdbc:postgresql://full.server.name/public
jdbc:postgresql:public
jdbc:postgresql://localhost/

But, despite the parameters, I always get the following error:

exception 
javax.servlet.ServletException: Couldn't open connection to database: 
Exception creating DataSource: org.hsql.jdbcDriver
at InfoServlet.init(Unknown Source)
at javax.servlet.GenericServlet.init(GenericServlet.java:258)
at 
org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:918)


{cut}

I have no idea why Tomcat wants to connect using hsql driver. I grepped 
through tomcat directory and found only one reference to this driver (in 
examples section). I removed event the sample section, restarted Tomcat but 
it didn't help. 

Does anyone know what is wrong? 

regards
Przem


--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




Re: Tomcat 4.0.4, jndi, jdbc and postgresql [long]

2002-07-02 Thread Przemyslaw Kowalczyk

On Tuesday 02 July 2002 14:00, Les Hughes wrote:
 Two things,

 In your server.xml
 user I think should be username
 and
 driverName has been deprecated in favour of url which needs the servername
 and DB name as well
 (as in something like jdbc:postgresql://full.server.name/mybookdb - or
 whatever the DB is called)

Ok. Now my configuration file looks as follows:

Context path=/bookstore1 docBase=bookstore1 debug=0
 reloadable=true crossContext=true
  Logger className=org.apache.catalina.logger.FileLogger
 prefix=localhost_bookstore1_log. suffix=.txt
  timestamp=true/
  Resource name=jdbc/BookDB auth=Container
type=javax.sql.DataSource/
  ResourceParams name=jdbc/BookDB
parameter
 nameusername/name
  valuejava/value
/parameter
parameter
  namepassword/name
  valuejava/value
/parameter
parameter
  namedriverClassName/name
  valueorg.postgresql.Driver/value
/parameter
parameter
  namedriverName/name
  valuejdbc:postgresql://willow.forest/public/value
/parameter
  /ResourceParams
/Context


 Are you *sure* you're using the right install of TC and that the server.xml
 has no reference to the hsql driver?

I'm absolutely sure. I even reinstalled whole tomcat (to cleanup everything)

 BTW - only got this working with Oracle and mySQL so most of this is
 guesswork based on those two exercises.

 Bye,

 Les
 P.S. You shouldn't open the connection in init() nor cache the connection
 BTW - use a pool instead :)

For sure I will, but now all that I want is to connect my servlet to database.

regards
przem

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




Re: Tomcat 4.0.4, jndi, jdbc and postgresql [long]

2002-07-02 Thread Przemyslaw Kowalczyk

On Tuesday 02 July 2002 14:53, Przemyslaw Kowalczyk wrote:

I came to another conclusion. Even if there was some reference to hsql driver 
in my server.xml it shouldn't affect my own servlet, as it uses its own 
context. Am I right?

przem


--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




Re: Tomcat 4.0.4, jndi, jdbc and postgresql [long]

2002-07-02 Thread Przemyslaw Kowalczyk

On Tuesday 02 July 2002 14:56, [EMAIL PROTECTED] wrote:
 Would you have other applications running in tomcat?

No, I've just started to learn, so there are other apps.

przem


--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




Re: Tomcat 4.0.4, jndi, jdbc and postgresql [long]

2002-07-02 Thread Przemyslaw Kowalczyk

On Tuesday 02 July 2002 15:00, [EMAIL PROTECTED] wrote:
 Is this normal :

 resource-ref
 res-ref-namejdbc/BookDB/res-ref-name
 res-typejavax.sql.DataSource/res-type
 res-authContainter/res-auth
 /resource-ref

 More especially : res-authContainter/res-auth : CONTAINTER?


You are right, there is a misseling, but correcting it didn't help much :-(

I'm still curious why tomcat wants a hsql driver even though it's not 
mentioned in any configuration file.

przem




--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




Re: Tomcat 4.0.4, jndi, jdbc and postgresql [long]

2002-07-02 Thread Przemyslaw Kowalczyk

On Tuesday 02 July 2002 15:06, Les Hughes wrote:
 web-app
   resource-ref
   descriptionDB Connection/description
   res-ref-namejdbc/TestDB/res-ref-name
   res-typejavax.sql.DataSource/res-type
   res-authContainer/res-auth
   /resource-ref
 /web-app

 The description is missing (but I dont have a DTD to had to tell whether
 this is optional) but other than that it's fine.

Neither adding description nor removing slashes helped.
I've checked the path in manual:
jdbc:postgresql:database
jdbc:postgresql://host/database
jdbc:postgresql://host:port/database

I wonder if there is a way to debug what exactly Tomcat does. What section of 
server.xml does it parse etc.

Does anyone tried to connect to postgresql and succeeded?

przem




--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




Re: Tomcat 4.0.4, jndi, jdbc and postgresql [long]

2002-07-02 Thread Przemyslaw Kowalczyk

On Tuesday 02 July 2002 15:16, Les Hughes wrote:
 Ignore the remove // comment - I was looking at my oracle notes :-)
 I really have no idea why it's trying to load the hsql driver if there's no
 ref in your
 server.xml

Ok, the full versions (I cut off all comments):

przem


server.xml

---cut---here
Server port=8005 shutdown=SHUTDOWN debug=0
  Service name=Tomcat-Standalone

Connector className=org.apache.catalina.connector.http.HttpConnector
   port=8080 minProcessors=5 maxProcessors=75
   enableLookups=true redirectPort=8443
   acceptCount=10 debug=0 connectionTimeout=6/
Engine name=Standalone defaultHost=localhost debug=0

  Logger className=org.apache.catalina.logger.FileLogger
  prefix=catalina_log. suffix=.txt
  timestamp=true/


  Realm className=org.apache.catalina.realm.MemoryRealm /

  Host name=localhost debug=0 appBase=webapps unpackWARs=true

Valve className=org.apache.catalina.valves.AccessLogValve
 directory=logs  prefix=localhost_access_log. 
suffix=.txt
 pattern=common/

Logger className=org.apache.catalina.logger.FileLogger
 directory=logs  prefix=localhost_log. suffix=.txt
timestamp=true/

Context path=/manager docBase=manager 
 debug=0 privileged=true/

Context path=/bookstore1 docBase=bookstore1 debug=0
 reloadable=true crossContext=true
  Logger className=org.apache.catalina.logger.FileLogger
 prefix=localhost_bookstore1_log. suffix=.txt
  timestamp=true/
  Resource name=jdbc/BookDB auth=Container
type=javax.sql.DataSource/
  ResourceParams name=jdbc/BookDB
parameter
 nameusername/name
  valuejava/value
/parameter
parameter
  namepassword/name
  valuejava/value
/parameter   
parameter
  namedriverClassName/name
  valueorg.postgresql.Driver/value
/parameter
parameter
  namedriverName/name
  valuejdbc:postgresql:/localhost/public/value
/parameter
  /ResourceParams
/Context 

  /Host

/Engine

  /Service


  Service name=Tomcat-Apache

Connector className=org.apache.catalina.connector.warp.WarpConnector
 port=8008 minProcessors=5 maxProcessors=75
 enableLookups=true
 acceptCount=10 debug=0/

Engine className=org.apache.catalina.connector.warp.WarpEngine
 name=Apache defaultHost=localhost debug=0 appBase=webapps

  Logger className=org.apache.catalina.logger.FileLogger
  prefix=apache_log. suffix=.txt
  timestamp=true/

  Realm className=org.apache.catalina.realm.MemoryRealm /

/Engine

  /Service

/Server

---cut---here

web.xml

---cut---here
!DOCTYPE web-app
PUBLIC -//Sun Microsystems, Inc.//DTD Web Application 2.3//EN
http://java.sun.com/dtd/web-app_2_3.dtd;

web-app
display-nameInfo Application/display-name
description
Just test application
/description
servlet
servlet-nameinfo/servlet-name
display-nameinfo/display-name
descriptionno description/description
servlet-classInfoServlet/servlet-class
/servlet
servlet-mapping
servlet-nameinfo/servlet-name
url-pattern/info/url-pattern
/servlet-mapping
session-config
session-timeout30/session-timeout
/session-config
resource-ref
descriptionDatabase Connection/description
res-ref-namejdbc/BookDB/res-ref-name
res-typejavax.sql.DataSource/res-type
res-authContainer/res-auth
/resource-ref
/web-app
---cut---here---

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




Re: Tomcat 4.0.4, jndi, jdbc and postgresql [long]

2002-07-02 Thread Przemyslaw Kowalczyk

On Tuesday 02 July 2002 15:43, [EMAIL PROTECTED] wrote:
 Do you have already connected to a postgresql db using a java app? Are you
 sure the parameters are correct? What is public? Where did you put the
 postgresql.jar?

Yes, without any problems from 'standalone' application. I'm able to query and 
update database, so parameters (url, username and password) are ok.

There is no postgresql.jar, only pgjdbc2.jar. I put it in ${tomcat-root}/lib 
directory.  I tried first to add a link named postgresql.jar and then I've 
renamed it but it didn't help :-(

 Do you have a file named hsql.jar? Can you remove it?

I don't have such file.


przem


--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]