best and simple way of login mechanism
Hi, I want to provide a login page for my web applicatioin. I used the memory realm, by making changes in the server.xml. But it started giving me Connection errors, and I was not able to see the web pages. Then I commented the Memory realms tag and then I was able to see the web pages correctly. I tried to use the JDBC realms, but it also gave me same problems. Can some body please look at the sample server.xml that I use for JDBC realm? I am using the realms for ROOT context only. What is the best way to provide the login page on tomcat. -Server.xml- !-- Example Server Configuration File -- !-- Note that component elements are nested corresponding to their parent-child relationships with each other -- !-- A Server is a singleton element that represents the entire JVM, which may contain one or more Service instances. The Server listens for a shutdown command on the indicated port. Note: A Server is not itself a Container, so you may not define subcomponents such as Valves or Loggers at this level. -- Server port=8005 shutdown=SHUTDOWN debug=0 !-- Comment these entries out to disable JMX MBeans support -- !-- You may also configure custom components (e.g. Valves/Realms) by including your own mbean-descriptor file(s), and setting the descriptors attribute to point to a ';' seperated list of paths (in the ClassLoader sense) of files to add to the default list. e.g. descriptors=/com/myfirm/mypackage/mbean-descriptor.xml -- Listener className=org.apache.catalina.mbeans.ServerLifecycleListener debug=0/ Listener className=org.apache.catalina.mbeans.GlobalResourcesLifecycleListener debug=0/ !-- Global JNDI resources -- GlobalNamingResources !-- Test entry for demonstration purposes -- Environment name=simpleValue type=java.lang.Integer value=30/ !-- Editable user database that can also be used by UserDatabaseRealm to authenticate users -- Resource name=UserDatabase auth=Container type=org.apache.catalina.UserDatabase description=User database that can be updated and saved /Resource ResourceParams name=UserDatabase parameter namefactory/name valueorg.apache.catalina.users.MemoryUserDatabaseFactory/value /parameter parameter namepathname/name valueconf/tomcat-users.xml/value /parameter /ResourceParams /GlobalNamingResources !-- A Service is a collection of one or more Connectors that share a single Container (and therefore the web applications visible within that Container). Normally, that Container is an Engine, but this is not required. Note: A Service is not itself a Container, so you may not define subcomponents such as Valves or Loggers at this level. -- !-- Define the Tomcat Stand-Alone Service -- Service name=Tomcat-Standalone !-- A Connector represents an endpoint by which requests are received and responses are returned. Each Connector passes requests on to the associated Container (normally an Engine) for processing. By default, a non-SSL HTTP/1.1 Connector is established on port 8080. You can also enable an SSL HTTP/1.1 Connector on port 8443 by following the instructions below and uncommenting the second Connector entry. SSL support requires the following steps (see the SSL Config HOWTO in the Tomcat 4.0 documentation bundle for more detailed instructions): * Download and install JSSE 1.0.2 or later, and put the JAR files into $JAVA_HOME/jre/lib/ext. * Execute: %JAVA_HOME%\bin\keytool -genkey -alias tomcat -keyalg RSA (Windows) $JAVA_HOME/bin/keytool -genkey -alias tomcat -keyalg RSA (Unix) with a password value of changeit for both the certificate and the keystore itself. By default, DNS lookups are enabled when a web application calls request.getRemoteHost(). This can have an adverse impact on performance, so you can disable it by setting the enableLookups attribute to false. When DNS lookups are disabled, request.getRemoteHost() will return the String version of the IP address of the remote client. -- !-- Define a non-SSL Coyote HTTP/1.1 Connector on port 8080 -- Connector className=org.apache.coyote.tomcat4.CoyoteConnector port=8080 minProcessors=5 maxProcessors=75 enableLookups=true redirectPort=8443 acceptCount=100 debug=0 connectionTimeout=2 useURIValidationHack=false disableUploadTimeout=true / !-- Note : To disable connection timeouts, set connectionTimeout value to -1 -- !-- Define a SSL Coyote HTTP/1.1 Connector on port 8443 -- !-- Connector
error shutting down the tomcat
Hi, I was making some changes to my server.xml (I was adding another context to it). I was also using the webpage of manager. But even after making changes I cannot see the newly context available in the manager window. I decided to restart tomcat using command line. But I am getting the follwing exception-- bash-2.03$ ./startup.sh Using CATALINA_BASE: /opt/aarora/jakarta-tomcat-4.1.29 Using CATALINA_HOME: /opt/aarora/jakarta-tomcat-4.1.29 Using CATALINA_TMPDIR: /opt/aarora/jakarta-tomcat-4.1.29/temp Using JAVA_HOME: /usr/java/j2sdk1.4.0 bash-2.03$ ./shutdown.sh Using CATALINA_BASE: /opt/aarora/jakarta-tomcat-4.1.29 Using CATALINA_HOME: /opt/aarora/jakarta-tomcat-4.1.29 Using CATALINA_TMPDIR: /opt/aarora/jakarta-tomcat-4.1.29/temp Using JAVA_HOME: /usr/java/j2sdk1.4.0 Catalina.stop: java.net.ConnectException: Connection refused java.net.ConnectException: Connection refused at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:295) at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:161) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:148) at java.net.Socket.connect(Socket.java:425) at java.net.Socket.connect(Socket.java:375) at java.net.Socket.init(Socket.java:290) at java.net.Socket.init(Socket.java:118) at org.apache.catalina.startup.Catalina.stop(Catalina.java:581) at org.apache.catalina.startup.Catalina.execute(Catalina.java:402) at org.apache.catalina.startup.Catalina.process(Catalina.java:180) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav a:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor Impl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:203) bash-2.03$ although starting up tomcat do not show any errors, but I cannot see that tomcat is working. Nothing is available on the web page, I get error saying page not available. I have even restored all the changes, but then alsp I get them same exception. Any suggestions?? Thanks. Avinash Arora - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
log in page using tomcat
Hi, Does tomcat provides any help in creating the log in page. I want to create a login page, that will accept same username and password specified in server.xml particular data source context (for logging to database) in the ResourceParams tag. Thanks. Avinash Arora - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
closing the statement and result set object
Hi, When we obtain the Statement object from the connection object is it necessary to close the statement object separately, when I am closing the connection object. I had an impression that when we close the Connection object the Statement and Result set objects get closed automatically. Am I correct? Thanks. Avinash Arora -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Monday, May 10, 2004 12:32 PM To: [EMAIL PROTECTED] Subject: tomcat-user Digest 10 May 2004 19:32:23 - Issue 4423 tomcat-user Digest 10 May 2004 19:32:23 - Issue 4423 Topics (messages 100528 through 100544): Re: url mapping problem with apache 100528 by: Cox, Charlie Re: Authentication with custom access control 100529 by: QM maxThreads 100530 by: Hollerman Geralyn M Re: tomcat clustering 100531 by: Filip Hanik - Dev tomcat connection pooling 100532 by: Ponnam Janiki Manager access problems 100533 by: Greg Adams Re: Directory recursion with mod_jk2. 100534 by: Brett Simpson 2.0.4 connector source? 100535 by: Daniel Gibby Re: Tomcat 5.0 + IIS 6 + Windows 2003 100536 by: Srinivas Kotapally 100541 by: Kannan Sundararajan Memory Options 100537 by: Paul Mitchell Muiltipul Tomcat 5.19 Servers on the same machine. 100538 by: Bond 100542 by: Yansheng Lin 100544 by: Emerson Cargnin Re: Tomcat 5 JK2 and IIS 5 100539 by: Emerson Cargnin Re: Session without Cookies 100540 by: Yansheng Lin Re: Cannot access certian jar files in common/lib 100543 by: Yansheng Lin Administrivia: To subscribe to the digest, e-mail: [EMAIL PROTECTED] To unsubscribe from the digest, e-mail: [EMAIL PROTECTED] To post to the list, e-mail: [EMAIL PROTECTED] -- - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
setting dbcp connection pool connections
Hi, How do we set up the number of connections that we want, while using dbcp connection pooling provided by tomcat. I think we have to configure some xml file. But don't know what changes we have to make in which file. Can any body give a sample file. Thanks. Avinash Arora - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: DB connection pool problem
Well I figured out the problem. The problem was that mysql-connector.jar was not in common/lib of tomcat, but it I had placed in the WEB-INF/lib of my application. Thanks for every body's suggestion. Also just asking curiosity if we keep same jar in both WEB-INF/lib and common/lib, will it create some problem. Thanks. Avinash Arora -Original Message- From: Daxin Zuo [mailto:[EMAIL PROTECTED] Sent: Wednesday, May 05, 2004 4:45 PM To: Tomcat Users List Subject: RE: DB connection pool problem Have you tried to put the configuration text in GlobalNamingResources instead of context block? To me, the message tells that the web.xml and java code is fine. The server.xml is not edited correctly. in you server.xml, you put ResourceParams name=jdbc/conversion, but where is the resource jdbc/conversion? -Original Message- From: Arora, Avinash [mailto:[EMAIL PROTECTED] Sent: Wednesday, May 05, 2004 4:07 PM To: Daxin Zuo; Tomcat Users List Subject: RE: DB connection pool problem Hi, Sorry I was messing up my code by making several changes. If I add that statement, I get the following SQL exception is generated Cannot create JDBC driver of class '' for connect URL 'null'. Any idea about what corrections I need to make. Avinash Arora -Original Message- From: Daxin Zuo [mailto:[EMAIL PROTECTED] Sent: Tuesday, May 04, 2004 4:29 PM To: Tomcat Users List Subject: RE: DB connection pool problem You have to add con = dataSource.getConnection(); after dataSource = (DataSource)ctx.lookup(jdbc/conversion); -Original Message- From: Arora, Avinash [mailto:[EMAIL PROTECTED] Sent: Tuesday, May 04, 2004 3:54 PM To: David Smith; Tomcat Users List Subject: RE: DB connection pool problem Sorry for creating the confusion. Actually I was seeing the connection object to be null for long time. But at last moment I made those silly changes to present it in a better way. Sorry about it. But now I printing the connection object and finding it to be null. I cannot understand, the reason for connection object to be null, even when datasource object is not null. Is it because that I am not able to connect to database? If yes what could be the reason. If I specify the attributes, using Direct JDBC by using Class.forName() and DriverManager.getConnection(), I can connect to data base and read all the values. But the problem comes when I use Connection pooling. Where shuld I look for correction?? -- Part of my code and JSP o/p - public LinkedList selectCP(){ LinkedList ll = new LinkedList(); Connection con = null; Statement stmt = null; ResultSet rs = null; DataSource dataSource = null; try{ Context init = new InitialContext(); Context ctx = (Context) init.lookup(java:comp/env); dataSource = (DataSource)ctx.lookup(jdbc/conversion); ll.add(dataSource object is); ll.add(dataSource); } catch(NamingException e){ System.out.println(Exception thrown is+e.getMessage()); ll.add(Naming Exception thrown); } finally{ if(dataSource == null){ ll.add(DataSource object is null); return ll; } else{ ll.add(Data source object is not null); } } try{ ll.add(Inside try.); ll.add(con is); ll.add(con); if(con == null){ ll.add(Inside try. Connection object found to be null); ll.add(con); return ll; } else{ ll.add(Connection object inside else is); ll.add(con);} } } catch(SQLException e) { System.err.println(SQL EXCEPTION+e.getMessage()); ll.add(SQL Exception ); ll.add(e.getMessage()); } catch(Exception e) { System.err.println( class not found exception+e.getMessage()); ll.add(Exception generated:); ll.add(e.getMessage()); } finally{ if(con == null) ll.add(Connection object is null); } try{ stmt.close(); } catch(Exception e){} try{ rs.close(); } catch(Exception e){} try{ con.close(); } catch(Exception e){} return ll; } ---O/P-- --- I am pasting the ll obtained on browser-- [dataSource object is, [EMAIL PROTECTED], Data source object is not null, Inside try., con is, null, Inside try. Connection object found to be null, null, Connection object is null] -Original Message
specifying location of confg file
Hi, How can we specify the location of config file, so that we don't have to hardcode it in our code. Thanks. Avinash Arora Avinash Arora -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, May 06, 2004 3:27 PM To: [EMAIL PROTECTED] Subject: tomcat-user Digest 6 May 2004 22:26:30 - Issue 4415 tomcat-user Digest 6 May 2004 22:26:30 - Issue 4415 Topics (messages 100374 through 100391): Re: Form method always a get. 100374 by: Wade Chandler 100375 by: Wade Chandler Re: Starting Tomcat from Apache... 100376 by: Paul Gregoire Directory recursion with mod_jk2. 100377 by: Brett Simpson Looking for a HOW-TO for connecting apache to tomcat 5 100378 by: Nathan Maves 100379 by: Shapira, Yoav (newbie q) Connector vs running standalone Tomcat as root 100380 by: Barnet Wagman 100381 by: Parsons Technical Services 100382 by: QM Re: DB connection pool problem 100383 by: Xtecuan! Ufo Senshi Dai Apolon Include file? 100384 by: Steven Garrett 100387 by: Jacob Kjome 100388 by: Steven Garrett 100389 by: Steven Garrett Mod-jk2 binaries availability for Apache 2.0.49 100385 by: Asif Chowdhary Mod-jk2 availability for Apache 2.0.49 100386 by: Asif Chowdhary 100390 by: Randy Re: Question about memory 100391 by: Wade Chandler Administrivia: To subscribe to the digest, e-mail: [EMAIL PROTECTED] To unsubscribe from the digest, e-mail: [EMAIL PROTECTED] To post to the list, e-mail: [EMAIL PROTECTED] -- - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: DB connection pool problem
Hi, Sorry I was messing up my code by making several changes. If I add that statement, I get the following SQL exception is generated Cannot create JDBC driver of class '' for connect URL 'null'. Any idea about what corrections I need to make. Avinash Arora -Original Message- From: Daxin Zuo [mailto:[EMAIL PROTECTED] Sent: Tuesday, May 04, 2004 4:29 PM To: Tomcat Users List Subject: RE: DB connection pool problem You have to add con = dataSource.getConnection(); after dataSource = (DataSource)ctx.lookup(jdbc/conversion); -Original Message- From: Arora, Avinash [mailto:[EMAIL PROTECTED] Sent: Tuesday, May 04, 2004 3:54 PM To: David Smith; Tomcat Users List Subject: RE: DB connection pool problem Sorry for creating the confusion. Actually I was seeing the connection object to be null for long time. But at last moment I made those silly changes to present it in a better way. Sorry about it. But now I printing the connection object and finding it to be null. I cannot understand, the reason for connection object to be null, even when datasource object is not null. Is it because that I am not able to connect to database? If yes what could be the reason. If I specify the attributes, using Direct JDBC by using Class.forName() and DriverManager.getConnection(), I can connect to data base and read all the values. But the problem comes when I use Connection pooling. Where shuld I look for correction?? -- Part of my code and JSP o/p - public LinkedList selectCP(){ LinkedList ll = new LinkedList(); Connection con = null; Statement stmt = null; ResultSet rs = null; DataSource dataSource = null; try{ Context init = new InitialContext(); Context ctx = (Context) init.lookup(java:comp/env); dataSource = (DataSource)ctx.lookup(jdbc/conversion); ll.add(dataSource object is); ll.add(dataSource); } catch(NamingException e){ System.out.println(Exception thrown is+e.getMessage()); ll.add(Naming Exception thrown); } finally{ if(dataSource == null){ ll.add(DataSource object is null); return ll; } else{ ll.add(Data source object is not null); } } try{ ll.add(Inside try.); ll.add(con is); ll.add(con); if(con == null){ ll.add(Inside try. Connection object found to be null); ll.add(con); return ll; } else{ ll.add(Connection object inside else is); ll.add(con);} } } catch(SQLException e) { System.err.println(SQL EXCEPTION+e.getMessage()); ll.add(SQL Exception ); ll.add(e.getMessage()); } catch(Exception e) { System.err.println( class not found exception+e.getMessage()); ll.add(Exception generated:); ll.add(e.getMessage()); } finally{ if(con == null) ll.add(Connection object is null); } try{ stmt.close(); } catch(Exception e){} try{ rs.close(); } catch(Exception e){} try{ con.close(); } catch(Exception e){} return ll; } ---O/P-- --- I am pasting the ll obtained on browser-- [dataSource object is, [EMAIL PROTECTED], Data source object is not null, Inside try., con is, null, Inside try. Connection object found to be null, null, Connection object is null] -Original Message- From: David Smith [mailto:[EMAIL PROTECTED] Sent: Tuesday, May 04, 2004 1:35 PM To: Tomcat Users List Subject: Re: DB connection pool problem Sorry about the last post. It's been a looonnng day and I didn't read it very well :-(. From what I see, you're comparing conn to null before even attempting to get a connection. Try comparing dataSource to null instead of conn in the second catch block. Then do dataSource.getConnection() if dataSource != null. --David David Smith wrote: I'm a bit confused on your code: try{ // load the driver class file //Class.forName(com.mysql.jdbc.Driver).newInstance(); //establishing the connection if(con == null){ ll.add(Inside 1st try. Connection object found to be null); Why are you doing a Class.forName call after getting a datasource object? I think you're mixing incompatible database access methods. Try doing
RE: DB connection pool problem
Hi friends, Thanks for your previous feedback. After adding several logging statements in my code, I have found that connection object is null. But dataSource object is not null. What can be reason for it?? Here is how I use it in my code-- public LinkedList testFunction(){ LinkedList ll = null; Connection con = null; Statement stmt = null; ResultSet rs = null; DataSource dataSource = null; try{ Context init = new InitialContext(); Context ctx = (Context) init.lookup(java:comp/env); dataSource = (DataSource)ctx.lookup(jdbc/conversion); ll.add(dataSource object is); ll.add(dataSource); } catch(NamingException e){ System.out.println(Exception thrown is+e.getMessage()); ll.add(Naming Exception thrown); } finally{ if(dataSource == null){ ll.add(DataSource object is null); return ll; } else{ ll.add(Data source object is not null); // return ll; } } try{ // load the driver class file //Class.forName(com.mysql.jdbc.Driver).newInstance(); //establishing the connection if(con == null){ ll.add(Inside 1st try. Connection object found to be null); } else{ ll.add(Inside 1st try. Connection object is not nul); con = dataSource.getConnection(); stmt = con.createStatement(); } finally{ if(con == null){ ll.add(Connection object is null); // return ll; } --Here is the output that I can see on my jsp page, where I try to print out the linklist obtained from the function above. elements of link list read from database are -[dataSource object is, [EMAIL PROTECTED], Data source object is not null, Inside 1st try. Connection object found to be null, Connection object is null] Thanks. Avinash Arora -Original Message- From: Daxin Zuo [mailto:[EMAIL PROTECTED] Sent: Monday, May 03, 2004 3:34 PM To: Tomcat Users List Subject: RE: DB connection pool problem I have just created a pool -- I hope it is really a pool. I used jtds jdbc driver to MS SQL Server on Windows. You may find some thing similar. Holp it helps. 1) bellow is the text in tomcat\conf\server.xml GlobalNamingResources Resource name=jdbc/DirectSQL auth=Container type=javax.sql.DataSource/ ResourceParams name=jdbc/DirectSQL parameter namefactory/name valueorg.apache.commons.dbcp.BasicDataSourceFactory/value /parameter parameter namemaxActive/name value255/value /parameter parameter namemaxIdle/name value10/value /parameter parameter namemaxWait/name value1/value /parameter parameter nameusername/name valueuser1/value /parameter parameter namepassword/name valuepasswd1/value /parameter parameter namedriverClassName/name valuenet.sourceforge.jtds.jdbc.Driver/value /parameter parameter nameurl/name valuejdbc:jtds:sqlserver://serverName:1433/value /parameter /ResourceParams ... 2) bellow is the text in tomcat\conf\Catalina\localhost\ROOT.XML --I create this file by myself Context path= docBase=ROOT debug=0 privileged=true !-- Link to the user database using dbc:jtds:sqlserver -- ResourceLink name=jdbc/DirectSQL global=jdbc/DirectSQL type=javax.sql.DataSource/ /Context This name is used in Java code. global is the name in xml file. they can be different. 3) my test jsp file is in \tomcat\webapps\ROOT\zuo\ Context ctx = new InitialContext(); if (ctx == null) { throw new Exception(Boom - No Context); } DataSource ds = (DataSource) ctx.lookup(java:comp/env/jdbc/DirectSQL); if (ds != null) con = ds.getConnection(); if (con != null){ str = select * from myTable; pStateSearch = con.prepareStatement(str, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY ); rs = pStateSearch.executeQuery(); That's all. -Original Message- From: Arora, Avinash [mailto:[EMAIL PROTECTED] Sent: Monday, May 03, 2004 3:10 PM To: Tomcat Users List Subject: DB connection pool problem Hi, I am also having the problem with the connection pools. Since I am writing an application first time by using connection pools, I created a test application DBTest. I edited my server.xml and web.xml (of my
RE: DB connection pool problem
Sorry for creating the confusion. Actually I was seeing the connection object to be null for long time. But at last moment I made those silly changes to present it in a better way. Sorry about it. But now I printing the connection object and finding it to be null. I cannot understand, the reason for connection object to be null, even when datasource object is not null. Is it because that I am not able to connect to database? If yes what could be the reason. If I specify the attributes, using Direct JDBC by using Class.forName() and DriverManager.getConnection(), I can connect to data base and read all the values. But the problem comes when I use Connection pooling. Where shuld I look for correction?? -- Part of my code and JSP o/p - public LinkedList selectCP(){ LinkedList ll = new LinkedList(); Connection con = null; Statement stmt = null; ResultSet rs = null; DataSource dataSource = null; try{ Context init = new InitialContext(); Context ctx = (Context) init.lookup(java:comp/env); dataSource = (DataSource)ctx.lookup(jdbc/conversion); ll.add(dataSource object is); ll.add(dataSource); } catch(NamingException e){ System.out.println(Exception thrown is+e.getMessage()); ll.add(Naming Exception thrown); } finally{ if(dataSource == null){ ll.add(DataSource object is null); return ll; } else{ ll.add(Data source object is not null); } } try{ ll.add(Inside try.); ll.add(con is); ll.add(con); if(con == null){ ll.add(Inside try. Connection object found to be null); ll.add(con); return ll; } else{ ll.add(Connection object inside else is); ll.add(con);} } } catch(SQLException e) { System.err.println(SQL EXCEPTION+e.getMessage()); ll.add(SQL Exception ); ll.add(e.getMessage()); } catch(Exception e) { System.err.println( class not found exception+e.getMessage()); ll.add(Exception generated:); ll.add(e.getMessage()); } finally{ if(con == null) ll.add(Connection object is null); } try{ stmt.close(); } catch(Exception e){} try{ rs.close(); } catch(Exception e){} try{ con.close(); } catch(Exception e){} return ll; } ---O/P-- --- I am pasting the ll obtained on browser-- [dataSource object is, [EMAIL PROTECTED], Data source object is not null, Inside try., con is, null, Inside try. Connection object found to be null, null, Connection object is null] -Original Message- From: David Smith [mailto:[EMAIL PROTECTED] Sent: Tuesday, May 04, 2004 1:35 PM To: Tomcat Users List Subject: Re: DB connection pool problem Sorry about the last post. It's been a looonnng day and I didn't read it very well :-(. From what I see, you're comparing conn to null before even attempting to get a connection. Try comparing dataSource to null instead of conn in the second catch block. Then do dataSource.getConnection() if dataSource != null. --David David Smith wrote: I'm a bit confused on your code: try{ // load the driver class file //Class.forName(com.mysql.jdbc.Driver).newInstance(); //establishing the connection if(con == null){ ll.add(Inside 1st try. Connection object found to be null); Why are you doing a Class.forName call after getting a datasource object? I think you're mixing incompatible database access methods. Try doing dataSource.getConnection() after getting a valid datasource instead. You'll be happier with the result. Take a look at the javadocs for javax.sql.DataSource for more info. --David Arora, Avinash wrote: Hi friends, Thanks for your previous feedback. After adding several logging statements in my code, I have found that connection object is null. But dataSource object is not null. What can be reason for it?? Here is how I use it in my code-- public LinkedList testFunction(){ LinkedList ll = null;Connection con = null; Statement stmt = null; ResultSet rs = null; DataSource dataSource = null; try{ Context init = new InitialContext
DB connection pool problem
Hi, I am also having the problem with the connection pools. Since I am writing an application first time by using connection pools, I created a test application DBTest. I edited my server.xml and web.xml (of my application in following way-- #added to server.xml Context path=/DBTest docBase=DBTest debug=0 reloadable=true ResourceParams name=jdbc/conversion parameter nameusername/name valueROOT/value /parameter parameter namepassword/name valuePASSWORD/value /parameter parameter namedriverClassName/name valuecom.mysql.jdbc.Driver/value /parameter parameter nameurl/name valuejdbc:mysql://localhost/DB/value /parameter /ResourceParams /Context #web.xml web-app descriptionMySQL Test App/description resource-ref res-ref-namejdbc/conversion/res-ref-name res-typejavax.sql.DataSource/res-type res-authContainer/res-auth /resource-ref /web-app And I added the following statements to my Java class, (which works fine, when I use the connection objects by hardcoding the username and db).-- Context init = new InitialContext(); Context ctx = (Context) init.lookup(java:comp/env); DataSource dataSource = (DataSource)ctx.lookup(jdbc/conversion); But even after, making these changes, I cannot read any thing from database. I was wondering what more changes I need to made. I also tried to run my JAVA class (DAO) from command line, but I get the following exception-- Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial I tried to print outs the place where exception occurs in my code and found that exception occurs at dataSource = (DataSource)ctx.lookup(jdbc/conversion); Can any body please comment on whats going on wrong? When I run from command line, is tomcat used, I don't think so? So where is the problem? Any ideas?? Avinash Arora - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
editing tomcat class path
) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2417) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:193) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:781) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:549) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:589) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:666) at java.lang.Thread.run(Thread.java:536) Apache Tomcat/4.1.29 Avinash Arora Avinash Arora - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
editing the class path w
) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2417) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:193) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:781) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:549) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:589) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:666) at java.lang.Thread.run(Thread.java:536) Apache Tomcat/4.1.29 Avinash Arora Avinash Arora - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]