Re: Tomcat 4.0.4, jndi, jdbc and postgresql [long]
hello Przemyslaw, les, On Wed, 03 Jul 2002 05:11:44 -0700 , Przemyslaw wrote: 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 i checked your idea to use DBCP and it is working, but i was not willing to give up on the problem. so i entered exactly the same jndi url as read on your example and voila no problem. so it seems we are not read the complete naming conventions or did not understand the doc. i could not find a hint what you have to type: java:comp/env/jdbc/Database instead of jdbc/Database. ^ so for now it's solved and i went back to find out what is better with DBCP. BTW: i changed server.xml and global web.xml !! best reagrds peter ;-) -- 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]
The model is very simple and as a coder you never see that DBCP is there instead of Tyrex or a direct connection. Let me know how you get on an I'll patch the documentation accordingly. Also I noticed that my howto has made it into CVS (thanks guys!) so if you grab a nightly build (probably tomorrow now) then you can follow those instructions. Good luck! Les -- 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]
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]
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]
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) Are you *sure* you're using the right install of TC and that the server.xml has no reference to the hsql driver? 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 :) -Original Message- From: Przemyslaw Kowalczyk [mailto:[EMAIL PROTECTED]] Sent: 02 July 2002 11:09 To: 'Tomcat Users List' Subject: Tomcat 4.0.4, jndi, jdbc and postgresql [long] 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
Re: Tomcat 4.0.4, jndi, jdbc and postgresql [long]
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]
Would you have other applications running in tomcat? -Original Message- From: Przemyslaw Kowalczyk [mailto:[EMAIL PROTECTED]] Sent: 02 July 2002 14:54 To: Tomcat Users List Subject: Re: Tomcat 4.0.4, jndi, jdbc and postgresql [long] 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] DISCLAIMER This e-mail and any attachments thereto may contain information which is confidential and/or protected by intellectual property rights and are intended for the sole use of the recipient(s) named above. Any use of the information contained herein (including, but not limited to, total or partial reproduction, communication or distribution in any form) by persons other than the designated recipient(s) is prohibited. If you have received this e-mail in error, please notify the sender either by telephone or by e-mail and delete the material from any computer. Thank you for your cooperation. -- 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]
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]
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? Andre Powroznik -Original Message- From: Przemyslaw Kowalczyk [mailto:[EMAIL PROTECTED]] Sent: 02 July 2002 12:09 To: 'Tomcat Users List' Subject: Tomcat 4.0.4, jndi, jdbc and postgresql [long] 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
RE: Tomcat 4.0.4, jndi, jdbc and postgresql [long]
Yep :-) Oh, I think there's a typo in the URL - remove the two // - this is all driver specific so it's a case of RTM :-) -Original Message- From: Przemyslaw Kowalczyk [mailto:[EMAIL PROTECTED]] Sent: 02 July 2002 14:00 To: Tomcat Users List Subject: Re: Tomcat 4.0.4, jndi, jdbc and postgresql [long] 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] -- 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]
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. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: 02 July 2002 14:00 To: [EMAIL PROTECTED] Subject: RE: Tomcat 4.0.4, jndi, jdbc and postgresql [long] 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? Andre Powroznik -Original Message- From: Przemyslaw Kowalczyk [mailto:[EMAIL PROTECTED]] Sent: 02 July 2002 12:09 To: 'Tomcat Users List' Subject: Tomcat 4.0.4, jndi, jdbc and postgresql [long] 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
Re: Tomcat 4.0.4, jndi, jdbc and postgresql [long]
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]
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]
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 Post your server.xml and web.xml and we'll both have a look. -Original Message- From: Przemyslaw Kowalczyk [mailto:[EMAIL PROTECTED]] Sent: 02 July 2002 14:13 To: Tomcat Users List Subject: Re: Tomcat 4.0.4, jndi, jdbc and postgresql [long] 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] -- 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]
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]
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? Do you have a file named hsql.jar? Can you remove it? -Original Message- From: Przemyslaw Kowalczyk [mailto:[EMAIL PROTECTED]] Sent: 02 July 2002 12:09 To: 'Tomcat Users List' Subject: Tomcat 4.0.4, jndi, jdbc and postgresql [long] 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
Re: Tomcat 4.0.4, jndi, jdbc and postgresql [long]
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 Post your server.xml and web.xml and we'll both have a look. I struggled for weeks (on and off) trying to figure out why Tyrex ALWAYS tries to load the hsql driver - in vain. Don't bother trying to get Tyrex to work - it just doesn't! (And neither does it pool connections) - you should try TC 4.1, which uses the jakarta-commons DBCP. DBCP works, and pools connections! Martin -- 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]
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]
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]
RE: Tomcat 4.0.4, jndi, jdbc and postgresql [long]
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. See http://marc.theaimsgroup.com/?l=tomcat-userm=102225547106556w=2 for my original mysql post as well. Resource name=jdbc/postgres auth=Container type=javax.sql.DataSource/ ResourceParams name=jdbc/postgres parameter namefactory/name valueorg.apache.commons.dbcp.BasicDataSourceFactory/value /parameter parameter namedriverClassName/name valueorg.postgresql.Driver/value /parameter parameter nameurl/name valuejdbc:postgresql://127.0.0.1:5432/mydb/value /parameter parameter nameusername/name valuemyuser/value /parameter parameter namepassword/name valuemypasswd/value /parameter parameter namemaxActive/name value20/value /parameter parameter namemaxIdle/name value10/value /parameter parameter namemaxWait/name value-1/value /parameter /ResourceParams -Original Message- From: Przemyslaw Kowalczyk [mailto:[EMAIL PROTECTED]] Sent: 02 July 2002 14:53 To: Tomcat Users List Subject: Re: Tomcat 4.0.4, jndi, jdbc and postgresql [long] 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] -- 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]
On Tue, 2002-07-02 at 08:47, Przemyslaw Kowalczyk wrote: 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 Przem, Here are the setting I have used with Tomcat 4.0.4, postgresql 7.2.1 jdk1.4 I had to put the postgresql.jar, commons-dbcp.jar, commons-pool.jar into the DIR/common/lib directory. SERVER.XML: Resource name=jdbc/tropicos auth=Container type=javax.sql.DataSource/ ResourceParams name=jdbc/tropicos parameter namefactory/name valueorg.apache.commons.dbcp.BasicDataSourceFactory/value /parameter parameternamemaxActive/namevalue100/value/parameter parameternamemaxIdle/namevalue3/value/parameter parameternamemaxWait/namevalue100/value/parameter parameternameusername/namevalueX/value/parameter parameternamepassword/namevalue/value/parameter parameter namedriverClassName/name valueorg.postgresql.Driver/value /parameter parameter nameurl/name valuejdbc:postgresql://localhost:5432/ids_tropicos/value /parameter /ResourceParams Then the web.xml cruft: resource-ref descriptionPostgreSQL DB Connection/description res-ref-namejdbc/tropicos/res-ref-name res-typejavax.sql.DataSource/res-type res-authContainer/res-auth /resource-ref -- Brian Millett Enterprise Consulting Group Shifts in paradigms (314) 205-9030 often cause nose bleeds. [EMAIL PROTECTED] Greg Glenn -- 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]
Hi, I notice that you are doing the JDBC lookup in the init function. This doesn't appear to work properly (at least on 4.1.6), move the initialisation code to the doGet/doPost and see if that helps. This cured my JNDI/JDBC problems. Regards. - Original Message - From: Przemyslaw Kowalczyk [EMAIL PROTECTED] To: 'Tomcat Users List' [EMAIL PROTECTED] Sent: Tuesday, July 02, 2002 11:08 AM Subject: Tomcat 4.0.4, jndi, jdbc and postgresql [long] 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
Re: Tomcat 4.0.4, jndi, jdbc and postgresql [long]
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 This last form is the most complete one. Anyway, that will not make a difference, since it is up to JDBC driver to parse this URL AND JDBC DRIVER WORKS. I wonder if there is a way to debug what exactly Tomcat does. What section of server.xml does it parse etc. I've tried running Tomcat under JBuilder. I did get into debugging session, but when it came to XML parser, it just, sort of, dropped into a hole. I needed sources for XML parser, too. At that point I've had had too much and decided to wait for DBCP. Does anyone tried to connect to postgresql and succeeded? Craig has done it and although he is one of the developers, he was unable to help us. I guess it is not just for fashion, that they have decided to drop Tyrex in favour of DBCP. Nix.